Good:
@* Comment *@
Bad:
<!-- Comment -->
@* Comment *@
<!-- Comment -->
MVC has a bunch of handy helpers that we can use to create our views more efficiently. One such helper are the display templates that are used within views.
@Html.DisplayFor(e => e.Username)
The DisplayFor(Func<TModel, TValue> expression) function uses the type of the property in the expression to display the property value.
<!-- DisplayFor on string UserName = "daniel.imms" --> <span class="field-validation-valid" data-valmsg-for="UserName" data-valmsg-replace="true">daniel.imms</span>
@using (Html.BeginForm())
{
// ...
}
It surrounds the markup inside the block with a <form> tag and includes attributes based on what is passed through the parameter list. The way it works is HtmlHelper.BeginForm() returns a MvcForm object which on creation uses HtmlHelper to write markup to the page. When the using block comes to an end the Dispose method on MvcForm is used to output the closing tag.Func<> parameter type presented in several places, particularly LINQ which uses it extensively. You may know how to use it but have you ever thought about what it is exactly and how to go about using it in your own functions?@functions
{
HtmlString PrintSomething()
{
return new HtmlString("Hello World");
}
}
Returning a HtmlString object will allow you to print to the screen.<div>@PrintSomething()</div>