Sunday, 15 July 2012

asp.net mvc - MVC @Html.DisplayForModel() different views -



asp.net mvc - MVC @Html.DisplayForModel() different views -

i've started larn mvc.

i know can create typed view in shared/displaytemplates, after returning list controller, can @html.displayformodel() , utilize template entire list.

however, if don't want model built in way i've specified in displaytemplate? how can create different display templates?

the obvious way seems to create template each object, like...

@foreach(var item in model) { @html.displayfor(x=>x, "alternativetemplate") }

..but you've got foreach, doesn't seem elegant.

you right, can utilize displayformodel overload takes string param template name. http://msdn.microsoft.com/en-us/library/ee430910(v=vs.98).aspx

you have have template defined under views/shared/displaytemplates exact name given in string.

asp.net-mvc

No comments:

Post a Comment