ASP MVC 3 Display List<> Name
i have this model
public class Registro
{
[DisplayName("Provincia")]
[Required]
public int ProvinciaID { get; set; }
public List<Provincia> rProvincia { get; set; }
}
Now what i need to do for show the Name of List<Provincia> rPr开发者_C百科ovincia
in my detalis view?, i was thinking that maybe @Html.DisplayFor(modelItem => item.rProvincia.Name)
, any idea?,
Thanks guys :)
No need to write any foreach
loops. In your main view simply:
@model AppName.Models.Registro
...
@Html.DisplayFor(x => x.rProvincia)
...
and then inside the display template ~/Views/Shared/DisplayTemplates/Provincia.cshtml
:
@model AppName.Models.Provincia
<div>
@Html.DisplayFor(x => x.Name)
</div>
This display template will be rendered for each item in the rProvincia
collection.
FIX:
public class Registro
{
[DisplayName("Provincia")]
[Required]
public int ProvinciaID { get; set; }
public virtual Provincia rProvincia { get; set; }
}
with virtual i got it
精彩评论