Different way to call controller from view
Syntax @Html.Action(“action”, “controller”, parameters)
Method : 1
@using (Html.BeginForm(“Save”,”ControllerName”, FormMethod.Post))
{
@Html.TextBoxFor(model => m.Name)
<input type=”submit” value=”Save” />
}
Note :
- “Save” be the name of the Html form. We can also use Ajax.BeginForm() instead of Html.BeginForm
- Html.BeginForm is nothing but Html form
Method : 2
From Jquery
1) var url = ‘@Url.Action(“ActionName”, “ControllerName”)’;
window.location = url;2) $(this).load(“@Url.Action(“ActionName”, “ControllerName”)”);
Note :
- 2nd way is used for loading the partialview to the mainview
Method : 3
@Html.ActionLink(“ActionLinkName”, “ActionName”, “ControllerName”)