Asp.NET MVC 传值原理
在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 经典书籍小弟不胜感激涕零。
在点击显示集合页面的时候 点击 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 经典书籍小弟不胜感激涕零。
...全文
相关推荐
asp.net mvc 设计思想的练习
表单传值在ASP.NET MVC中主要依赖于HTTP的POST请求。当你在表单中设置`action`属性为Controller的某个动作时,表单提交时会向该动作发送POST请求,携带表单字段的值。
C# post 传值 和接收值实例
本文将深入探讨C#中如何实现POST请求的传值与接收值。一、POST请求的原理POST请求常用于向服务器提交表单数据,它将数据封装在请求体中,然后发送到指定的URL。
ASP.NET分页通用组件 支持很多自定义格式和传值方式
**灵活性**:这个通用组件不仅适用于ASP.NET的Web Forms,也可能适应于MVC或者ASP.NET Core框架,因为它的设计是跨平台和跨版本的,这使得它在不同类型的项目中都能发挥效用。
详解ASP.NET MVC 下拉框的传值的两种方式
本文主要介绍了ASP.NET MVC框架中下拉框(DropDownList)的两种传值方式,分别通过控制器(Controller)向视图(View)传递数据并进行绑定。在ASP.NET Web
基于ASP.NET MVC项目实例
学习路线**为了理解这个基于ASP.NET MVC的项目,你可以按照以下步骤进行学习:- **了解基本概念**:首先,你需要熟悉MVC模式的基本原理,以及ASP.NET MVC框架的关键组件。


