繁体   English   中英

ASP.Net MVC提交表单找不到方法 - 不能使用香草表格?

[英]ASP.Net MVC Submit Form Doesn't Find Method - Can't Use Vanilla Form?

我的表格如下:

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

该操作也用于引用视图,因此我会将'submitForm'更改为更合适的内容,如@Dai所建议的那样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM