mvc3.0 Html.BeginForm() submit提交后为什么control取实体为空呢
@modelMVC3Test1.Models.Person@{ViewBag.Title="修改人员";Layout="~/Views/Shared/_Layout.cs...
@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();
} 展开
2个回答
展开全部
这里其实是反射 因为我没有添加属性 所以没有取到值 请教一下是什么意思??回送的只是MODEL实体啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你先将person换成formcollection看看表格返回值了没有
追问
谢谢你的回答 这个问题已经解决了 formconllection是可以取到值得 实体也是可以取到值得,这里其实是反射 因为我没有添加属性 所以没有取到值 不过还是感谢参与的人 给你分了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询