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”)
Leave A Comment