Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Html.Action?

I am trying to understand how to use:

@Html.Action("GetOptions", ) 

What I would like to do is to pass a call to my controller and pass the parameters:

pk = "00" and rk = "00" 

Can someone explain how I can do that with the Html.Action

like image 250
Samantha J T Star Avatar asked Jan 16 '12 00:01

Samantha J T Star


People also ask

How does HTML action work?

This Html. Action renders partial view as an HTML string so we can store it in another string variable. It is string return type method so first it returns result as a string then renders result to response.

What is the difference between HTML action and HTML RenderAction?

The difference between the two is that Html. RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount of HTML) whereas Html. Action returns a string with the result.

What is the use of RenderAction in MVC?

RenderAction(HtmlHelper, String, String, RouteValueDictionary) Invokes the specified child action method using the specified parameters and controller name and renders the result inline in the parent view.


1 Answers

You should look at the documentation for the Action method; it's explained well. For your case, this should work:

@Html.Action("GetOptions", new { pk="00", rk="00" }); 

The controllerName parameter will default to the controller from which Html.Action is being invoked. So if you're trying to invoke an action from another controller, you'll have to specify the controller name like so:

@Html.Action("GetOptions", "ControllerName", new { pk="00", rk="00" }); 
like image 60
Nadir Muzaffar Avatar answered Oct 06 '22 01:10

Nadir Muzaffar