ASP.Net MVC 提交表单找不到方法 - 无法使用原版表单?



>我有一个表格如下:

<form action='@Url.Action("submitForm", "Home")'>
    <fieldset>
        <legend>User Details</legend>
        <input type="checkbox" name="authorisedCheckbox" value="Authorised" id="authCheck" />Authorised<br />
        <input type="checkbox" name="enabledCheckbox" value="Enabled" id="eCheck" />Enabled<br />
    </fieldset>
    <input type="submit" value="Save Changes" name="Save Changes">
    <button type="button">Cancel</button>
</form>

这将调用控制器中的方法:

    [HttpPost]
    public ActionResult submitForm(string authorisedCheckbox, string enabledCheckbox)
    {
        System.Diagnostics.Debug.WriteLine("input values: ");
        System.Diagnostics.Debug.WriteLine(authorisedCheckbox);
        System.Diagnostics.Debug.WriteLine(enabledCheckbox);
       //some other processing will be done here
        return View();
    }

但是当点击按钮时,表单会给出 404 未找到错误。我见过使用@using(Html.BeginForm("method","controller"((的帖子 - 这是使用 ASP.NET MVC调用控制器方法的唯一方法吗?

感谢 @Stephen Muecke 指出简单的事情就是将 method='post' 添加到标签中。

该操作也用于引用视图,因此我将按照@Dai的建议将"submitForm"更改为更合适的内容。

最新更新