【发布时间】:2017-11-02 07:14:12
【问题描述】:
我有一个 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.
我完全按照 stack-overflow 上的帖子中所说的那样做:asp.net mvc form not posting parameter values
有什么办法可以解决这个错误?我确定如果我得到表单值,那么我可以将它们插入数据库。
【问题讨论】:
-
你为什么使用“SaveButton”? (在 Content(Request.Form["SaveButton"]);) - 您试图从提交 btn 中读取值 - 没有意义。
-
不,它只是为了看到我从表单发布操作中获得了一些价值......否则没有任何意义。
-
您可以尝试删除此行:new { ReturnUrl = ViewBag.ReturnUrl }
-
只需在 beginform 中将“HomeController”更改为“Home”即可...
-
哦,没看过
标签: c# asp.net asp.net-mvc forms asp.net-mvc-4