Monday, September 24, 2012

Razor Helpers

Razor helpers work just like functions in C# and JS. Create a function (and pass parameters to it if needed) and call it to draw the HTML.


Example:
@helper ShowName(string Name)
    {
          <p> hello @Name <p>
}

and then to use it

ShowName("Ammar")
ShowName("Mike")

The HTML will transplate to
<p> hello Ammar <p>
<p> hello Mike<p>

The output will show:
Hello Ammar
Hello Mike