Asp.NET MVC 传值原理
狂奔小蜗牛 2012-06-27 11:29:56 在ASp.NET
在点击显示集合页面的时候 点击 Edit 跳转至 以下页面
这个是页面代码 <body>
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.id) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.id) %>
<%= Html.ValidationMessageFor(model => model.id) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.Name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.Name) %>
<%= Html.ValidationMessageFor(model => model.Name) %>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
<div>
<%= Html.ActionLink("Back to List", "Index") %>
</div>
在编辑之后 点击 Save的时候 Controller下的edit代码如下
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
moder mo = new moder();
UpdateModel(mo, collection.ToValueProvider());
if (moderTest.update(mo))
{
return RedirectToAction("Index");
}
else
{
return RedirectToAction("Index");
}
}
catch
{
return View();
}
}
例如 随意一条的 ID=7 此时 edit方法中的idie 方法中 的id为 7 并且collection 也有了数据
我是想知道 这块 id 和collection 的数据是通过什么原理传过来的。
顺便给我推荐几本 Asp.MVC 经典书籍小弟不胜感激涕零。