c# - Linq average, parameter function -


@foreach (var item in model) {       @html.actionlink(item.rates.average(item => item.rate)), "showrates", "track", new { track_nr = @item.track_nr, album_id=@item.album_id}, null)  <br> } 

i trying show average of rates, rates table in database consists of integers in collumn rate. visual studio telling me have give function parameter. have no idea how create function?

adding these functions view make ugly, rather add aproperty of model , calculation in controller before sending data view.

public class albumviewmodel {   public int album_id { set;get;}   public string track_nr { set;get;}   public decimal average_rate{ set;get;}  } 

your action method

public actionresult getalbums() {    var albums=rep.getalbmums();    foreach(var album in albums)    {        album.average_rate=album.rates.average();    }    return view(albums);     } 

and in clean view,

@foreach (var item in model) {      @html.actionlink(item.average_rate, "showrates", "track", new { track_nr = @item.track_nr, album_id=@item.album_id}, null)     } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -