asp.net mvc - get the name of model and title of another model in view -


i want name of model genre , title of model list in partial view @genre.lists.title doesn't work genre model

  public class genre {     public int genreid { get; set; }     public string name { get; set; }     public string description { get; set; }     public list<list> lists { get; set; } } 

and list model

 [bind(exclude = "listid")] public class list {     [scaffoldcolumn(false)]     public int listid { get; set; }     [displayname("genre")]     public int genreid { get; set; }     [displayname("maker")]     public int makerid { get; set; }     [required(errormessage = "an list title required")]     [stringlength(160)]     public string title { get; set; }     [required(errormessage = "price required")]     [range(0.01, 100.00,errormessage = "price must between 0.01 , 100.00")]     public decimal price { get; set; }     [displayname("list url")]     [stringlength(1024)]     public string listurl { get; set; }     public genre genre { get; set; }     public maker maker { get; set; }     public virtual list<orderdetail> orderdetails { get; set; } } 

and actionresult

  public actionresult navbar()     {          var genres = storedb.genres.include("lists").tolist();            return partialview("navbar",genres);     } 

and partialview

    @model ienumerable<store.models.genre>     @foreach (var genre in model)     {         @genre.name         @genre.lists.title     } 

@genre.lists of type list<list>, not list (by way, rename class somehow, it's easy confuse standard library class of name).

so either need foreach loop iterate on @genre.lists or can first element @genre.lists[0].title. it's want achieve. example, use string.join:

@model ienumerable<store.models.genre> @foreach (var genre in model) {     <text>         @genre.name         @string.join(", ", genre.lists.select(x => x.title))     </text> } 

or write real html. again, depends want output be.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -