Asp.NET MVC 传值原理

狂奔小蜗牛 狂奔小蜗牛 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在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 经典书籍小弟不胜感激涕零。

...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
狂奔小蜗牛
.NET社区 62,271 成员 668,968 内容