Inline helper in Asp.net MVC
Inline helper in Asp.net MVC always work in same page.The main purpose of inline helper is to create a helper in anywhere in page in body section and call anywhere, where we want to use that helper. Please check teh below example for reference.
Example:
Here i have created myhelper which will take a string from a list and display. So first we need to create new helper by anyname lie here myhelper . myhelper will take data from list in string format and from foreach loop, we will display . we need to call this method in page anywhere by just helpername like here @myhelper
Code:
<div>
@helper myhelper(string[] str)
{
<ul>
@foreach (var item in str)
{
<li>@item</li>
<br />
}
</ul>
}
</div>
<div>
<lable>No of users in list</lable>
<div>
@myhelper(new string[] {"Rajiv","Rajesh"})
</div>
Comments
Post a Comment