Asp.net Mvc Codeplex Preview 5 第二篇 Controller&Filter的新特性
来源:互联网 发布:网络用语zl是什么意思 编辑:程序博客网 时间:2024/05/01 08:32
下载:http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16775
上篇: Asp.net Mvc Codeplex Preview 5 第一篇 Helper的新特性
BindingHelperExtensions.UpdateFrom改为UpdateModel
使用方法(缺点:如果表单里存在MyModel里不存在的字段就会报错)
var x = new MyModel();
this.TryUpdateModel(x, Request.Form.AllKeys);
或(缺点:一个一个写太麻烦)
var x = new MyModel();
this.TryUpdateModel(x, new[] {"IDX", "Name"});
优点:如果你有定义HtmlHelper.ValidationMessage那么它将会自动为你判空,详见上篇文章
var x = new MyModel();
this.TryUpdateModel(x, Request.Form.AllKeys);
或(缺点:一个一个写太麻烦)
var x = new MyModel();
this.TryUpdateModel(x, new[] {"IDX", "Name"});
优点:如果你有定义HtmlHelper.ValidationMessage那么它将会自动为你判空,详见上篇文章
当然,你也可以通过this.TryUpdateModel(x, new[] {"IDX", "Name"},"Account");这种方式来获取不同的Model.
上述 TryUpdateModel返回是否绑定成功的bool值,如果确定无误,可使用 UpdateModel
Action提供了数组参数
View:
<%using (Html.Form("home", "save", FormMethod.Post)) {%>
<%=Html.CheckBox("like") %>
<%=Html.CheckBox("like") %>
<%=Html.CheckBox("like") %>
<%=Html.CheckBox("like") %>
<%=Html.SubmitButton() %>
<%}%>
<%=Html.CheckBox("like") %>
<%=Html.CheckBox("like") %>
<%=Html.CheckBox("like") %>
<%=Html.CheckBox("like") %>
<%=Html.SubmitButton() %>
<%}%>
Action:
public ActionResult Save(string[] like)
{
ViewData["Message"] = string.Join("", like);
return View("Index");
}
{
ViewData["Message"] = string.Join("", like);
return View("Index");
}
这样是可以取到like的值的
AcceptVerbs Filter
这个Filter可以让我们定义Action的访问方式
[AcceptVerbs("Post")]
public ActionResult Save()//只有Post才能访问
或
[AcceptVerbs("Post","GET")]//Post或Get都能访问,但其它方式不能访问
public ActionResult Save()
public ActionResult Save()//只有Post才能访问
或
[AcceptVerbs("Post","GET")]//Post或Get都能访问,但其它方式不能访问
public ActionResult Save()
ActionName Filter
为一个方法定义它的ActionName
如HomeController中定义
[ActionName("MyAction")]
public ActionResult Save()
{
return View("Index");
}
public ActionResult Save()
{
return View("Index");
}
则/home/save不能访问
一定要/home/myaction才可以访问
- Asp.net Mvc Codeplex Preview 5 第二篇 Controller&Filter的新特性
- Asp.net Mvc Codeplex Preview 5 第二篇 Controller&Filter的新特性
- Asp.net Mvc Codeplex Preview 5 第一篇 Helper的新特性
- Asp.net Mvc Codeplex Preview 5 第一篇 Helper新特性
- Asp.net Mvc Codeplex Preview 5 源代码及MVCContrib4pv5发布
- Asp.net Mvc Codeplex Preview 5 第三篇 实现Action参数传递繁杂类型
- Asp.net Mvc Codeplex Preview 5 第三篇 实现Action参数传递繁杂类型
- ASP.NET MVC CodePlex Preview 4 Installer + Source + Changed
- ASP.NET MVC V2 Preview 1 新特性初探
- ASP.NET AJAX CodePlex Preview 3的代码解析
- ASP.NET MVC CodePlex Preview 4 安装包,代码及更新内容说明
- ASP.NET MVC CodePlex Preview 4 安装包,代码及更新内容说明
- asp.net mvc的Routing、Controller、Filter学习笔记
- ASP.NET MVC preview 1升级到ASP.NET MVC preview 2的一些更改
- ASP.NET MVC 3 新特性
- ASP.NET MVC 3新特性
- asp.net mvc 之旅—— 第二站 窥探Controller下的各种Result
- Asp.net MVC各个类的说明(Preview 4)
- Crystal Reports 10: The Complete Reference
- Sams Teach Yourself AJAX in 10 Minutes
- Delphi部份函数,命令,属性中文说明
- Mastering Enterprise JavaBeans 3.0
- Software Engineering Measurement
- Asp.net Mvc Codeplex Preview 5 第二篇 Controller&Filter的新特性
- Software Configuration Management: A Clear Case for IBM Rational Clearcase And Clearquest Ucm
- Mastering Microsoft Office Access 2003
- 关于PHP你可能不知道的-PHP的事件驱动化设计
- Asp.net Mvc Codeplex Preview 5 第三篇 实现Action参数传递繁杂类型
- WAP: A Beginner's Guide
- Java All-In-One Desk Reference For Dummies
- 如何通过ODBC访问excel文件
- Undocumented Windows 2000 Secrets: A Programmer's Cookbook