MVC 4:不明确的行动请求

时间:2014-05-28 15:24:08

标签: asp.net-mvc-4

我有以下代码:

@using (Html.BeginForm("FolderChange", "EdiSender", FormMethod.Post, new {id = "ediFilesForm"}))
{
    var directoriesSelectList = new SelectList(Model.Directories);
    @Html.DropDownListFor(m => m.SelectedDirectory, directoriesSelectList, new {@Id = "Directories",     
    @style = "width:Auto;", @size = 20, onchange = "$('#ediFilesForm').submit()", name = "action:FolderChange"})

    var ediFilesSelectList = new SelectList(Model.EdiFileNames);
    @Html.DropDownListFor(m => m.SelectedEdiFile, ediFilesSelectList, new {@Id = "EdiFileNames",       
    @style = "width:Auto;", @size = 20})
}
<br/>

<form action="" method="post">
    <input type="submit" value="Send" name="action:Send" />
    <input type="submit" value="Delete" name="action:Delete" />
    <input type="submit" value="Refresh" name="action:Refresh" />
</form>

Here is a part of the controller:

    [HttpPost]
    [ActionName("FolderChange")]
    public ActionResult FolderChange(EdiFileModel ediFileModel)
    {
        ediFileModel = Load(ediFileModel.SelectedDirectory);
        return View("Index", ediFileModel);
    }
...

    [HttpPost]
    [MultipleButton(Name = "action", Argument = "Send")]
    public ActionResult Send(EdiFileModel ediFileModel)
    {
        ....
        return View("Index", ediFileModel);
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MultipleButtonAttribute : ActionNameSelectorAttribute
{
    public string Name { get; set; }
    public string Argument { get; set; }

    public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
    {
        var isValidName = false;
        var keyValue = string.Format("{0}:{1}", Name, Argument);
        var value = controllerContext.Controller.ValueProvider.GetValue(keyValue);

        if (value != null)
        {
            controllerContext.Controller.ControllerContext.RouteData.Values[Name] = Argument;
            isValidName = true;
        }

        return isValidName;
    }
}

当我按下任何按钮时,我收到以下消息:

  

当前的行动请求&#39; FolderChange&#39;在控制器类型&#39; EdiSenderController&#39;以下操作方法之间不明确:   System.Web.Mvc.ActionResult在EdiSimulatorWebSender.Controllers.EdiSenderController类型上发送(EdiSimulatorWebSender.Models.EdiFileModel)   Ed.SimulatorWebSender.Controllers.EdiSenderController类型的System.Web.Mvc.ActionResult FolderChange(EdiSimulatorWebSender.Models.EdiFileModel)

你能帮我理解我的看法有什么问题吗?

感谢。

1 个答案:

答案 0 :(得分:1)

确保在控制器上将post属性添加到post方法

public ActionResult FolderChange ... for the get

[HttpPost]
public ActionResult FolderChange... for the post