I’m fixing bugs for some application, and I need help understanding the following lines of code:
Here,
View:
@Html.RenderControlText("WFD_CONSENT")
Controller:
public static MvcHtmlString RenderControlText(this HtmlHelper htmlHelper, string controlType)
{
return htmlHelper.Action("ControlText", new { controlType = controlType });
}
The parameter controlType = "WFD_CONSENT" here.
I can’t get what the function htmlhelper.Action() is doing here.
Logically, this function RenderControlText() should be fetching some data from somewhere, but it doesn’t look like it. I’m at a dead end here.
This method RenderControlText() should fetch some text which I’ve saved somewhere, and display it.
EDIT: The Action() method has the follwing parameters: action-name and object routevalues?
What’s the second part: new { controlType = controlType } ? What does this routevalues do??
Take a look at the following blog post from Phil Haack where he explains child actions in details.
The Html.Action helper basically executes a child action. A child action is a standard controller action except that it could be rendered in parallel with the execution of the main request.
Html.Action("SomeAction", "SomeController")means that theSomeActionwill be executed onSomeControllerand the result of execution of this action rendered to the output.In contrast:
Html.Action("SomePartial")means that theSomePartialwill directly be rendered to the output without the execution of any child controller and action.But in both cases all the processing happens in a single client request. It’s just that you have the primary controller action that is executed and rendered a view and inside this view you used the Html.Action helper to instantiate a child controller and action (which could return for example a partial view) and the result of the execution of this view is directly inserted into the output.