我在注册页面上有一个带有提交按钮的表单,按下时无法使用,已经使用了一段时间了吗?我在 creat 方法上放了一个断点,它没有被调用
这是控制器中的创建方法
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);
这是视图
@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")
}