Thursday, June 6, 2013

Add DIV tag to ASP.NET MVC VIEW based on a Condition


@using (Html.BeginForm())
{
    int count=0;
   
    if(count>1)
    {
        @Html.Raw("<div>Count is larger than 1");
                                                }
                     else
                     {
                     @Html.Raw("<div>Count is less than 1</div>");
                     }
}

Code above will add a div tag based on the count variable value. Html.Raw returns a HTML string and the browser out put the HTML.

No comments:
Write comments
Recommended Posts × +