Site icon Dotnet Helpers

Different way to call controller from view using MVC Razor

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 :

Method : 2

From Jquery

1) var url = ‘@Url.Action(“ActionName”, “ControllerName”)’;
window.location = url;

2) $(this).load(“@Url.Action(“ActionName”, “ControllerName”)”);

Note :

Method : 3

@Html.ActionLink(“ActionLinkName”, “ActionName”, “ControllerName”)

 

 

 

Exit mobile version