javascript - ASP.Net MVC 提交表单找不到方法 - 无法使用普通表单?

标签 javascript c# asp.net asp.net-mvc forms

我有一个表格如下:

<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>

这会调用 Controller 中的方法:

    [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 调用 Controller 方法的唯一方法吗?

最佳答案

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

该操作还用于引用 View ,因此我将按照 @Dai 的建议将“submitForm”更改为更合适的内容。

关于javascript - ASP.Net MVC 提交表单找不到方法 - 无法使用普通表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43904484/

相关文章:

javascript - 如何重新定义 'this' 并重用另一个类的方法。多态性

c# - 如何访问 Web 窗体中 GridView 模板字段的属性

c# - 如何在 ASP.NET MVC 中使用分部 View ?

c# - 同步更新调用期间乐观并发异常

c# - 为什么 ASP.NET/Visual Studio Web 开发服务器这么慢?

JavaScript 验证

javascript - 如何根据 form-validator jquery 插件中的条件更改 errorMess 值

asp.net MVC 5 托管设置

asp.net - 用于 ASP.NET 的 Youtube API v3 工作示例

javascript - HighChartTable.js 仅限 yAxis 整数