Tuesday, November 12, 2013

If you need a "method" within a Razor view you may nest a new helper within the view to accomplish as much.

@helper HideDesk(Fixture fixture){if (fixture == Fixture.Desk)
   {<text>Table</text>}else{<text>@fixture.ToString()</text>}}

 
 

Could be used like this:

@Html.Raw(String.Format("<div id=\"item13\" style=\"background-image:
   url('/Content/{0}.png');\"></div>", HideDesk(@Model.Fixture13)))

 
 

Note that I jammed the helper onto one line to ensure no extra spacing sabotaged my effect.

No comments:

Post a Comment