[索引页]
[源码下载]
返璞归真 asp.net mvc (5) - Action Filter, UpdateModel, ModelBinder, Ajax, Unit Test
作者:webabcd
介绍
asp.net mvc 之 Action Filter, UpdateModel, ModelBinder, Ajax, Unit Test
- Action Filter - 在 Controller 层对信息做过滤。如何实现自定义的 Action Filter
- UpdateModel - 根据参数自动为对象的属性赋值
- ModelBinder - 定义如何绑定 Model,DefaultModelBinder 实现了 IModelBinder ,其可以根据名称自动将参数赋值到对象对应的属性上
- Ajax - 在 asp.net mvc 中使用 ajax
- Unit Test - 在 asp.net mvc 中使用单元测试
示例
1、asp.net mvc 自带的 Action Filter 的演示
FilterDemoController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;

using MVC.Models;

namespace MVC.Controllers
自定的 Action Filter 的实现
MyFilter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Web.Mvc;

namespace MVC
Details.aspx
2、应用 UpdateModel 的 Demo
UpdateModelController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;

namespace MVC.Controllers
Details.aspx
3、演示什么是 ModelBinder
ModelBinderController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;

namespace MVC.Controllers
Details.aspx
4、使用 ajax 的 Demo
<p>
Ajax
<script src="http://www.cnblogs.com/Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<br />
<!-- AjaxHelper 简要说明 -->
<%= Ajax.ActionLink(
"ProductId 为 1 的详情页",
"Details",
"Product",
new { id = 1 },
new AjaxOptions { UpdateTargetId = "ajax" }
)
%>
</p>
<div id="ajax" />
5、在 VS 中做单元测试
ProductControllerTest.cs
using MVC.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using System.Web.Mvc;

using MVC.Models;
using System.Collections.Generic;

namespace MVC.Tests
OK
[源码下载]
相关文章: