html beginform mvc中的多个提交表单

时间:2016-08-29 12:19:05

标签: asp.net-mvc razor html.beginform

尝试制作多个提交表单,但出现错误The current request for action 'EditAccount' on controller type 'AccountController is ambiguous between the following action methods。我怎样才能解决这个问题?这是代码

属性:

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>&nbsp;Add New</button>

}

1 个答案:

答案 0 :(得分:2)

试试这个,它会起作用。基于didUpdateValueForCharacteristicname调用该函数。

value

.cshtml

@using (Html.BeginForm("ActionName",new {@class = "form-horizontal"})) { <button type="submit" class="btn btn-w-m btn-primary" name="Account" value="Edit">Save</button> <button type="submit" class="btn btn-w-m btn-primary" name="Account" value="AddNew" ><i class="fa fa-plus" ></i>&nbsp;Add New</button> }

.cs