asp.net-mvc – asp.net mvc通用控制器
发布时间:2020-05-24 06:19:52 所属栏目:asp.Net 来源:互联网
导读:我正在考虑在ASP.NET MVC中实现一个通用控制器. PlatformObjectControllerT 其中T是(生成)平台对象. 这可能吗?有经验/文件吗? 一个相关的问题是如何产生的URL. 是的,你只是不能直接使用它,但你可以继承它并使用孩子 这里是我使用的: public class CruderTE
|
我正在考虑在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“记住我”的cookie
- asp.net – SQL Server 2005:事务死锁
- ASP.net c#替换字符串不起作用
- asp.net – 我可以使用一种模式来编辑MVC3应用程序中的下拉
- asp.net-mvc – 可靠地处理ASP.NET MVC模型绑定错误
- asp.net-mvc – ASP.NET MVC:使用EditorFor()和枚举的默认
- asp.net-mvc-3 – 在MVC3中对Webgrid行进行内联编辑
- asp.net-mvc – 使用@ Html.Partial渲染usercontrol(cshtml
- asp.net – 如何在MVC4的部分视图中添加脚本?
- asp.net-mvc – 文件上传MVC
推荐文章
站长推荐
- .net – IIS 6.0和ASPX中的404自定义错误不起作用
- asp.net-mvc-3 – 从HttpContext.Current访问Tem
- asp.net-mvc-2 – Asp.net MVC标签
- 如何在ASP.Net项目中包含jQuery?
- 在ASP.NET中设置ECommerce
- asp.net – IIS7中的SQL Server和Windows身份验证
- asp.net-core – 如何在部署asp.net核心应用程序
- asp.net – 我可以在GoDaddy上使用NHibernate吗?
- ASP.NET URL重写
- asp.net – 使用StartMode =“AlwaysRunning”在
热点阅读
