本文介绍了提交按钮未正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单提交一个注册页面时pressed,一直盯着它,而现在这是行不通的按钮?我把一个破发点上的科瑞方法,它不会被调用。
这是科瑞梅托德控制器
公众的ActionResult的Create()
{
返回查看();
} //
// POST:/ RegsterDetails /创建 [HttpPost]
公众的ActionResult创建(用户用户)
{
如果(ModelState.IsValid)
尝试
{
db.Users.Add(用户);
db.SaveChanges();
返回RedirectToAction(RegisterStats,RegisterStats);
}
赶上(例外)
{
返回查看();
}
返回查看(用户);
这是该视图
@model Fitness_Friend.Web.Models.User@ {
ViewBag.Title =RegisterDetails;
布局=〜/查看/共享/ _Layout.cshtml
}< H2> RegisterDetails< / H>@using(Html.BeginForm()){
@ Html.AntiForgeryToken()
@ Html.ValidationSummary(真) <&字段集GT;
<传奇>用户< /传说> < DIV CLASS =编辑标记>
@ Html.LabelFor(型号=> model.FirstName)
< / DIV>
< DIV CLASS =主编场>
@ Html.EditorFor(型号=> model.FirstName)
@ Html.ValidationMessageFor(型号=> model.FirstName)
< / DIV> < DIV CLASS =编辑标记>
@ Html.LabelFor(型号=> model.LastName)
< / DIV>
< DIV CLASS =主编场>
@ Html.EditorFor(型号=> model.LastName)
@ Html.ValidationMessageFor(型号=> model.LastName)
< / DIV> < DIV CLASS =编辑标记>
@ Html.LabelFor(型号=> model.DOB)
< / DIV>
< DIV CLASS =主编场>
@ Html.EditorFor(型号=> model.DOB)
@ Html.ValidationMessageFor(型号=> model.DOB)
< / DIV> < DIV CLASS =编辑标记>
@ Html.LabelFor(型号=> model.Address)
< / DIV>
< DIV CLASS =主编场>
@ Html.EditorFor(型号=> model.Address)
@ Html.ValidationMessageFor(型号=> model.Address)
< / DIV> < DIV CLASS =编辑标记>
@ Html.LabelFor(型号=> model.Email)
< / DIV>
< DIV CLASS =主编场>
@ Html.EditorFor(型号=> model.Email)
@ Html.ValidationMessageFor(型号=> model.Email)
< / DIV> < DIV CLASS =编辑标记>
@ Html.LabelFor(型号=> model.Gender)
< / DIV>
< DIV CLASS =主编场>
@ Html.EditorFor(型号=> model.Gender)
@ Html.ValidationMessageFor(型号=> model.Gender)
< / DIV> < DIV CLASS =编辑标记>
@ Html.LabelFor(型号=> model.UserName)
< / DIV>
< DIV CLASS =主编场>
@ Html.EditorFor(型号=> model.UserName)
@ Html.ValidationMessageFor(型号=> model.UserName)
< / DIV> &所述p为H.;
<输入类型=提交名称=创造价值=注册详情/>
&所述; / P>
< /字段集>
}< DIV>
@ Html.ActionLink(返回目录,索引,家)
< / DIV>@section脚本{
@ Scripts.Render(〜/包/ jqueryval)
}
解决方案
由于某些原因,你的表格是不是挂钩到你的动作正确。为了消除一些对正在发生的事情的可能性,我建议你实际上指定什么行动和控制器的形式将利用张贴到。
@ Html.BeginForm(CREATEUSER,ControllerWithCreateUserMethod)
{
//此处插入您的HTML。
//这里提交按钮
<输入类型=提交值=提交/>
}
I have a form with a submit button on a registration page that will not work when pressed, have been at it for a while now? I put a break point on the creat method and it doesn't get called
This is the Creat Metod in the controller
public ActionResult Create()
{
return View();
}
//
// POST: /RegsterDetails/Create
[HttpPost]
public ActionResult Create(User user )
{
if(ModelState.IsValid)
try
{
db.Users.Add(user);
db.SaveChanges();
return RedirectToAction("RegisterStats", "RegisterStats");
}
catch(Exception)
{
return View();
}
return View(user);
This is The View
@model Fitness_Friend.Web.Models.User
@{
ViewBag.Title = "RegisterDetails";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>RegisterDetails</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>User</legend>
<div class="editor-label">
@Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FirstName)
@Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LastName)
@Html.ValidationMessageFor(model => model.LastName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DOB)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DOB)
@Html.ValidationMessageFor(model => model.DOB)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Address)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Address)
@Html.ValidationMessageFor(model => model.Address)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Gender)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Gender)
@Html.ValidationMessageFor(model => model.Gender)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</div>
<p>
<input type="Submit" name="Create" value="Register Details" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index","Home")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
解决方案
For some reason, your form is not hooking up to your action properly. In order to eliminate some of the possibilities for what is going on, I suggest that you actually specify what Action and Controller the form will use to post to.
@Html.BeginForm("CreateUser", "ControllerWithCreateUserMethod")
{
//insert your HTML here.
//submit button here
<input type="submit" value="Submit"/>
}
这篇关于提交按钮未正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!