Action HTML Helper in MVC3



  • The Action Url helper is exactly like ActionLink, but does not return an anchor tag.
  • Action helper executes a separate controller action and displays the result.
  • Action helper provides more flexibility and reuse as controller action can build a different model and make use of a separate controller context.
It has following Overloads :

Overload 1 :


This overload accepts the name of the action method.

Syntax :

<p>
    @Html.Action("About")
</p>

UI :




The about view is rendered as a part of View return by Home Action method. 


Rendered HTML :

   <span>
       /Home/Index
   </span>


Overload 2 :


This overload accepts the actionName and routeValues. The route values can be received as parameter at action method.

Syntax :

<p>
    @Html.Action("About", new { id=6})
</p>

In the above code, we are passing id attribute as route value.


Action Method :




The action method About accepts the id parameter, which we passed from view using route values. The id value received is assigned to viewbag and returned, which we will see on UI.

UI :



Overload 3 :


Syntax :

<p>
    @Html.Action("About",dic)
</p>



Action Method :


UI :




Overload 4 :


This overload accepts action name and controller name as well. We need to specify controller name, when we want to direct to action method of different controller.

Syntax :

<p>
    @Html.Action("About","Home")
</p>


UI :






Overload 5 :


This overload accepts action name, controller name and route values.

Syntax :

<p>
    @Html.Action("About", "Home", new { id=6})
</p>

UI :





Overload 6 :


This overload accepts action name, controller name and RouteValueDictionary object of route values.

Syntax :

<p>
    @Html.Action("About", "Home", dic)
</p>




Action Method :




UI :







0 comments:

Post a Comment