asp.net-mvc – asp.net mvc通用控制器
发布时间:2020-12-15 22:48:44 所属栏目:asp.Net 来源:网络整理
导读:我正在考虑在ASP.NET MVC中实现一个通用控制器. PlatformObjectControllerT 其中T是(生成)平台对象. 这可能吗?有经验/文件吗? 一个相关的问题是如何产生的URL. 解决方法 是的,你只是不能直接使用它,但你可以继承它并使用孩子 这里是我使用的: public clas
我正在考虑在ASP.NET MVC中实现一个通用控制器.
PlatformObjectController<T> 其中T是(生成)平台对象. 这可能吗?有经验/文件吗? 一个相关的问题是如何产生的URL. 解决方法
是的,你只是不能直接使用它,但你可以继承它并使用孩子
这里是我使用的: public class Cruder<TEntity,TInput> : Controller where TInput : new() where TEntity : new() { protected readonly IRepo<TEntity> repo; private readonly IBuilder<TEntity,TInput> builder; public Cruder(IRepo<TEntity> repo,IBuilder<TEntity,TInput> builder) { this.repo = repo; this.builder = builder; } public virtual ActionResult Index(int? page) { return View(repo.GetPageable(page ?? 1,5)); } public ActionResult Create() { return View(builder.BuildInput(new TEntity())); } [HttpPost] public ActionResult Create(TInput o) { if (!ModelState.IsValid) return View(o); repo.Insert(builder.BuilEntity(o)); return RedirectToAction("index"); } } 和用法: public class FieldController : Cruder<Field,FieldInput> { public FieldController(IRepo<Field> repo,IBuilder<Field,FieldInput> builder) : base(repo,builder) { } } public class MeasureController : Cruder<Measure,MeasureInput> { public MeasureController(IRepo<Measure> repo,IBuilder<Measure,MeasureInput> builder) : base(repo,builder) { } } public class DistrictController : Cruder<District,DistrictInput> { public DistrictController(IRepo<District> repo,IBuilder<District,DistrictInput> builder) : base(repo,builder) { } } public class PerfecterController : Cruder<Perfecter,PerfecterInput> { public PerfecterController(IRepo<Perfecter> repo,IBuilder<Perfecter,PerfecterInput> builder) : base(repo,builder) { } } 代码在这里: 更新: 现在使用这种方法:http://prodinner.codeplex.com (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何从(object sender,ListViewItemEventArgs e
- asp.net-mvc – 使用Html.BeginForm与querystring
- asp.net – 如何防止PDF文档下载到用户PC?
- asp.net-mvc – 注销后,如果浏览器返回按钮,那么它返回最后
- asp.net-mvc-3 – 剃刀索引视图中的条件格式
- castle-windsor – 如何在ASP.NET 4 RC WebAPI中将依赖注入
- asp.net-mvc – ASP MVC中的“@”是什么意思/做什么?
- ASP.NET:jQuery AJAX’data’param问题
- asp.net-mvc – 是否可以模拟/伪造扩展方法?
- ASP.NET Excel导出编码问题
推荐文章
站长推荐
- asp.net-mvc-3 – 使用ViewModel时不显示MVC3自定
- asp.net-core – 恢复AspNet标识核心包时出错
- 会话的最大长度是什么ASP.net 4.0会话ID – 存储
- asp.net – 我的支付方式按钮不会链接到支付朋友
- asp.net-mvc – 可以使用“Bundle.Include”(在A
- asp.net-mvc-5 – MVC 5&ASP.NET身份 – 实现
- azure – 错误System.BadImageFormatException服
- ASP.NET MVC2不在HtmlAttributes中用短划线替换下
- ASP.NET MVC3中基于权限的授权
- asp.net-web-api – 是否可以从消息处理程序访问
热点阅读