Creating reusable method using @helper in MVC Razor

 Creating reusable method using @helper in MVC Razor

The @helper enables you to easily create re-usable helper methods that can encapsulate output function.

This enable code reuse and more readable.It bind blocks of Markup (HTML) and Server-side logic into reusable page-level methods.

Syntax : @helper MethodName(parameters) { … }

Inside the this method we can integrate both HTML and Server-side code


@helper CretingMultipleRows(int loopvalue)
<table><tr id=@loopvalue><td>Calling helper Method :
<table><tr><th>Creting Multiple Row</th></tr>
@for (int loop_index = 0; loop_index < 5; loop_index++)

Output :



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s