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

前端 未结 1 482
暖寄归人
暖寄归人 2020-12-11 12:39

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 re

相关标签:
1条回答
  • 2020-12-11 13:12

    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.

    0 讨论(0)
提交回复
热议问题