ASP.NET MVC 3: Automatically generating view while adding controller (without Entity Framework)

泪湿孤枕 提交于 2019-12-17 20:43:22

问题


I am trying to learn MVC. I want to automatically generate the required view code as and when I add a controller. This is possible if I select the option “Controller with read/write actions and views, using Entity Framework” . However I am not using Entity Framework. How can I achieve the similar behavior without using Entity Framework? And why it is unable to automatically generate the view when I don’t use Entity Framework?

Also, is there any good MVC3 tutorial that does not use Entity Framework (with code download available) ?

Reference

  1. How do I configure ASP.net MVC to Scaffold using ADO.net dataservice?

  2. Levergaing T4Scaffolding for WCF Web API

  3. ASP.NET MVC 3 and NHibernate Scaffolding

  4. Scaffold your ASP.NET MVC 3 project with the MvcScaffolding package

  5. Once again LINQ to SQL or Entity Framework for new MVC 3 project

  6. MVC Scaffolding for WCF Services

  7. Create a Dropdown List for MVC3 using Entity Framework (.edmx Model) & Razor Views && Insert A Database Record to Multiple Tables


回答1:


You might find some of what you're looking for in Steve Sanderson's MvcScaffolding package

Nuget

Install-Package MvcScaffolding

After installing (it will probably install some EF requirements) you could scaffold basic CRUD views for your model as follows assuming a model type MySweetModel

Scaffold Views MySweetModel

Please note this command will not create the controller class, but should create the following views under /Views/MySweetModel

  • _CreateOrEdit.cshtml
  • Create.cshtml
  • Delete.cshtml
  • Details.cshtml
  • Edit.cshtml
  • Index.cshtml

It looks like you might be able to override the default T4 templates, but I've never used MvcScaffolding outside the scope of EF. It's also possible someone has already done this for your persistence layer e.g. NHibernate or whatever you're using. I'd search a bit before implementing your own templates.



来源:https://stackoverflow.com/questions/9328197/asp-net-mvc-3-automatically-generating-view-while-adding-controller-without-en

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!