我在控制器中有2个按钮和2个动作,在一个按钮上单击我需要处理一个动作,另一个按钮单击我需要处理另一个动作,我该如何实现这个
我给出了不同的值和相同的名称
<input type="Submit" class="button" value="Search" name="btnName" />
<input type="Submit" class="button" value="Save" name="btnName" />
答案 0 :(得分:0)
您必须使用Html.Action链接
@Html.ActionLink("Save", "NameOfAction", "NameOfController")
这是一个ajax链接
Ajax.ActionLink(
"Save",
"NameOfAction",
"NameOfController",
new { id = "AnyIdIfNeeded" },
new AjaxOptions
{
OnFailure = "JavascriptThatHandlesFailed",
HttpMethod = "GET",
UpdateTargetId = "SomeDivIdToUpdate",
LoadingElementId = "IdOfDivThatShowsLoading",
OnSuccess = "JavascriptMethodThatHandlesSuccess"
}
).ToHtmlString());
一个简单的表格
using (Html.BeginForm("ManageRoles", "ManageRoles", FormMethod.POST, new { id = "SearchForm" }))
{
<a href="javascript:void(0);" onclick="document.getElementById('SearchForm').submit();">Save</a>
}