c# - MVC4 Razor template like -
hello have simple question think,
i have cshtml like:
<div id="box"> @if (model.view == "item1") { <div id="item1"> ... </div> } else { <div id="item2"> ... </div> } <div id="itemdescription"> ... </div> </div>
where pass parameter via model display content depending on parameter, because rest of document same in both cases.
is there better way achieve this?
thanks!
not really; way of doing things. if div id matches value of model.view
, shorten this:
<div id="box"> <div id="@(model.view)"> ... </div> <div id="itemdescription"> ... </div> </div>
otherwise, approach fine. per von v's comment, might want partial views if contained markup long-winded (or need repeat logic in multiple places):
http://www.asp.net/mvc/videos/mvc-2/how-do-i/how-do-i-work-with-data-in-aspnet-mvc-partial-views
Comments
Post a Comment