@model MVC3Test1.Models.Person
@{
ViewBag.Title = "修改人员";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
修改人员</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>人员信息</legend>
@Html.HiddenFor(model => model.ID)
<div class="editor-label">@Html.LabelFor(model => model.Name)</div>
<div class="editor-field">@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">@Html.LabelFor(model=>model.Age)</div>
<div class="editor-field">@Html.EditorFor(model=>model.Age)
@Html.ValidationMessageFor(model=>model.Age)</div>
<p>
<input type="submit" value="保存" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("返回列表", "Index")
</div> //修改方法
// POST: /Person/Edit/5 [HttpPost]
public ActionResult Edit(int id, Person person)
{
try
{
foreach (Person item in ls)
{
if (item.ID.Equals(id))
{
item.Name = person.Name;
item.Age = person.Age;
return RedirectToAction("Index");
}
}
}
catch
{
return View();
}
return View();
}
@{
ViewBag.Title = "修改人员";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
修改人员</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>人员信息</legend>
@Html.HiddenFor(model => model.ID)
<div class="editor-label">@Html.LabelFor(model => model.Name)</div>
<div class="editor-field">@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">@Html.LabelFor(model=>model.Age)</div>
<div class="editor-field">@Html.EditorFor(model=>model.Age)
@Html.ValidationMessageFor(model=>model.Age)</div>
<p>
<input type="submit" value="保存" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("返回列表", "Index")
</div> //修改方法
// POST: /Person/Edit/5 [HttpPost]
public ActionResult Edit(int id, Person person)
{
try
{
foreach (Person item in ls)
{
if (item.ID.Equals(id))
{
item.Name = person.Name;
item.Age = person.Age;
return RedirectToAction("Index");
}
}
}
catch
{
return View();
}
return View();
}
<tr>
<td>
@Html.Label("生日")
</td>
<td>
@Html.TextBoxFor(model => model.Birthday, new { onclick = "displayCalendar(Birthday,'yyyy-mm-dd',this)" })
</td>
</tr>
<tr>
<td>
@Html.Label("QQ号码")
</td>
<td>
@Html.EditorFor(model => model.QQ)
@Html.ValidationMessageFor(model => model.QQ)
</td>
</tr>
<tr>
<td>
@Html.Label("手机号码")
</td>
<td>
@Html.EditorFor(model => model.LongTel)
@Html.ValidationMessageFor(model => model.LongTel)
</td>
</tr>
<tr>
<td>
@Html.Label("手机短号")
</td>
<td>
@Html.EditorFor(model => model.ShortTel)
@Html.ValidationMessageFor(model => model.ShortTel)
</td>
</tr>
其他的EditorFor都可以在后台获得页面输入的值,就是LongTel始终是0。
搞不懂怎么回事