ASP.NET MVC 3:添加控制器时自动生成视图(无实体框架) [英] ASP.NET MVC 3: Automatically generating view while adding controller (without Entity Framework)

查看:19
本文介绍了ASP.NET MVC 3:添加控制器时自动生成视图(无实体框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习 MVC.我想在添加控制器时自动生成所需的视图代码.如果我选择选项具有读/写操作和视图的控制器,使用实体框架",这是可能的.但是我没有使用实体框架.如何在不使用实体框架的情况下实现类似的行为?以及为什么在不使用Entity Framework的情况下无法自动生成视图?

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?

另外,有没有不使用实体框架的好的MVC3教程(提供代码下载)?

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

参考

  1. 如何使用 ADO.net 数据服务将 ASP.net MVC 配置为 Scaffold?

利用 WCF Web API 的 T4Scaffolding

Levergaing T4Scaffolding for WCF Web API

ASP.NET MVC 3 和 NHibernate 脚手架

使用 MvcScaffolding 包搭建您的 ASP.NET MVC 3 项目

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

再次为新的 MVC 3 项目使用 LINQ to SQL 或实体框架

WCF 服务的 MVC 脚手架

MVC Scaffolding for WCF Services

使用实体框架(.edmx 模型)为 MVC3 创建下拉列表 &剃刀视图&&将一条数据库记录插入多个表

推荐答案

您可能会在 Steve Sanderson 的 MvcScaffolding 包

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

Install-Package MvcScaffolding

安装后(它可能会安装一些 EF 要求),假设模型类型为 MySweetModel

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

请注意此命令将创建控制器类,但应在/Views/MySweetModel

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

  • _CreateOrEdit.cshtml
  • 创建.cshtml
  • 删除.cshtml
  • 详细信息.cshtml
  • 编辑.cshtml
  • 索引.cshtml

您似乎可以覆盖默认的 T4 模板,但我从未在 EF 范围之外使用过 MvcScaffolding.也有可能有人已经为您的持久层执行了此操作,例如NHibernate 或任何你正在使用的.在实现您自己的模板之前,我会搜索一下.

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.

这篇关于ASP.NET MVC 3:添加控制器时自动生成视图(无实体框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆