ASP.NET MVC 提交表单数据到数据库

ASP.NET MVC Submit form data into database

我有一个 ASP.NET mvc 应用程序,其视图如下:

@using (Html.BeginForm("FormSubmit", "HomeController", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal" }))
    {    
            <fieldset>

                <!-- Form Name -->
                <legend>Survey Form</legend>

                <br>
                <br>

                 <centre> <p> This is a survey for User X. <p>
                 </centre>

                    <!-- Multiple Radios -->
                    <div class="form-group">
                        <label class="col-md-4 control-label" for="q1">Any Plans to attend college?</label>
                        <div class="col-md-4">
                            <div class="radio">
                                <label for="q1-0">
                                    <input type="radio" name="Q1" id="q1-0" value="1">
                                    Yes
                                </label>
                            </div>
                            <div class="radio">
                                <label for="q1-1">
                                    <input type="radio" name="Q1" id="q1-1" value="2">
                                    No
                                </label>
                            </div>
                        </div>
                    </div>

      <input type="submit" name="SaveButton" value="Save" align="center">  

       </fieldset>

 }

我在 HomeController 中创建了控制器:

   [HttpPost]
   public ActionResult FormSubmit(int Q1)
    {
        return Content(Request.Form["SaveButton"]);
       //  return RedirectToAction("Index");
    }

现在,当我尝试按钮时,它给了我一个:

  Server Error in '/surveyapps' Application.
  The resource cannot be found.

我完全按照这个 post 在堆栈溢出中所说的做了:

有什么方法可以解决这个错误?我确定如果我得到表单值,那么我可以将它们插入数据库。

在您看来,将 HomeController 更改为 Home

像这样:

@using (Html.BeginForm("FormSubmit", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal" }))

框架会自动处理带有 "Controller" 后缀的问题