C# 如何知道ASP.Net中对象的最大值
因此,我的html中有:C# 如何知道ASP.Net中对象的最大值,c#,asp.net-mvc,C#,Asp.net Mvc,因此,我的html中有: @foreach (Artist artist in Model.artist) { <tr> <td>@artist.attr.rank</td> <td><a href="@artist.url" target="_blank">@artist.name</a></td> <td><div ... aria-v
@foreach (Artist artist in Model.artist)
{
<tr>
<td>@artist.attr.rank</td>
<td><a href="@artist.url" target="_blank">@artist.name</a></td>
<td><div ... aria-valuenow="@artist.playcount" aria-valuemin="0" aria-valuemax="???">@artist.playcount</div></td>
</tr>
}
@foreach(Model.Artist中的艺术家)
{
@艺人
@艺术家,剧目
}
其中Mode.artist是:
public List<Artist> artist { get; set; }
公共列表艺术家{get;set;}
艺术家的定义如下:
public class Artist
{
public string name { get; set; }
public int playcount { get; set; }
public string mbid { get; set; }
public string url { get; set; }
public string streamable { get; set; }
public List<Image> image { get; set; }
[JsonProperty("@attr")]
public Rank attr { get; set; }
}
公共类艺术家
{
公共字符串名称{get;set;}
public int playcount{get;set;}
公共字符串mbid{get;set;}
公共字符串url{get;set;}
公共字符串可流化{get;set;}
公共列表映像{get;set;}
[JsonProperty(“@attr”)]
公共秩属性{get;set;}
}
我希望aria valuemax=“???”成为所有艺术家的最大值
我该怎么做?
谢谢您可以使用:
...aria-valuemax="@Model.artist.Max(x=> x.playcount)"...
但是,最好将其声明为循环外部的变量:
@{ int maxPlayCount = Model.artist.Max(x=> x.playcount); }
然后,从这个变量中获取值:
...aria-valuemax="@maxPlayCount"...
您可以使用以下选项:
...aria-valuemax="@Model.artist.Max(x=> x.playcount)"...
但是,最好将其声明为循环外部的变量:
@{ int maxPlayCount = Model.artist.Max(x=> x.playcount); }
然后,从这个变量中获取值:
...aria-valuemax="@maxPlayCount"...
您可以使用以下选项:
...aria-valuemax="@Model.artist.Max(x=> x.playcount)"...
但是,最好将其声明为循环外部的变量:
@{ int maxPlayCount = Model.artist.Max(x=> x.playcount); }
然后,从这个变量中获取值:
...aria-valuemax="@maxPlayCount"...
您可以使用以下选项:
...aria-valuemax="@Model.artist.Max(x=> x.playcount)"...
但是,最好将其声明为循环外部的变量:
@{ int maxPlayCount = Model.artist.Max(x=> x.playcount); }
然后,从这个变量中获取值:
...aria-valuemax="@maxPlayCount"...
当您在循环中使用它时,您可能希望计算一次该值并在循环中使用它(以避免O(n*n)性能)。可以在模型中为其添加特性:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
然后在设置了artist
属性后,在模型构造函数中设置它:
MaxPlayCount = artist.Max(a => a.playcount);
在标记中,从模型中获取值:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
当您在循环中使用它时,您可能希望计算一次该值并在循环中使用它(以避免O(n*n)性能)。可以在模型中为其添加特性:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
然后在设置了artist
属性后,在模型构造函数中设置它:
MaxPlayCount = artist.Max(a => a.playcount);
在标记中,从模型中获取值:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
当您在循环中使用它时,您可能希望计算一次该值并在循环中使用它(以避免O(n*n)性能)。可以在模型中为其添加特性:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
然后在设置了artist
属性后,在模型构造函数中设置它:
MaxPlayCount = artist.Max(a => a.playcount);
在标记中,从模型中获取值:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
当您在循环中使用它时,您可能希望计算一次该值并在循环中使用它(以避免O(n*n)性能)。可以在模型中为其添加特性:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
然后在设置了artist
属性后,在模型构造函数中设置它:
MaxPlayCount = artist.Max(a => a.playcount);
在标记中,从模型中获取值:
public int MaxPlayCount { get; private set; }
... aria-valuemax="@Model.MaxPlayCount" ...
模型可能没有
Max
方法,我想你的意思是model.artist.Max
。模型可能没有Max
方法,我想你的意思是model.artist.Max
。模型可能没有Max
方法,我想你的意思是Model.artist.Max
。模型可能没有Max
方法,我想你的意思是Model.artist.Max
。