May 25, 2018

Razor tips & tricks (ASP.NET Core 2.0)

Some quick tips besides what you can quickly find on net...

@(xxxxxxxxxxx)

Anything you place in brackets will be printed:

So:

@(ViewBag.IsActive = true)

; will print True and assign value:


This saved my day many time:
@{Html.PartailView("xxxxxx");}

For some reason when mixing html and Razor PartialView method is not recognized so this solves problem.

For JS use :

<text>
$(document).ready();
</text>

Don't forget also:

@Html.Raw("class='mycssclass'")

And semicolon:

@:

No comments:

Post a Comment