0
試圖做出多個提交表單,但有錯誤The current request for action 'EditAccount' on controller type 'AccountController is ambiguous between the following action methods
。我怎樣才能解決這個問題?這裏的代碼多次提交表單在html中beginform mvc
屬性:
從控制器public class HttpParamActionAttribute : ActionNameSelectorAttribute
{
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
{
if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
return true;
var request = controllerContext.RequestContext.HttpContext.Request;
return request[methodInfo.Name] != null;
}
}
方法:
[HttpPost]
[HttpParamAction]
public virtual async Task<ActionResult> AddNew(AccountModel model)
{ ... }
[HttpPost]
[HttpParamAction]
public virtual async Task<ActionResult> EditAccount(AccountModel model)
{ ... }
,並查看
@using (Html.BeginForm(new {@class = "form-horizontal"}))
{
<button type="submit" class="btn btn-w-m btn-primary" name="EditAccount">Save</button>
<button type="submit" class="btn btn-w-m btn-primary" name="AddNew" ><i class="fa fa-plus"></i> Add New</button>
}
我猜你不理解你的按鈕都在做你的方法參數是什麼,或者什麼(他們需要'爲了value'屬性後的值) 。建議你看看[這個問題/答案](http://stackoverflow.com/questions/30970159/net-mvc4-actionnameselectorattribute-multiple-buttons-within-view-is-not-workin) –
我覺得這篇文章將有您的問題的答案:http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework – Monah