A number of folks wanted the code from my talk at Mix, specifically the "complete application" example with CRUD (Create, Read, Update, Delete) so here it is.
许多人都想从我在Mix上的演讲中获得代码,特别是带有CRUD(创建,读取,更新,删除)的“完整应用程序”示例,因此就在这里。
It's nothing pretty to look at, but it makes a number of points with ASP.NET MVC:
看上去没什么好看的,但是使用ASP.NET MVC可以说明很多问题:
- It uses the Default Routes to do everything. 它使用默认路由来做所有事情。
- It uses a ViewUserControl to avoid duplication in a Form. 它使用ViewUserControl来避免在Form中重复。
- It includes the PagedList<T> that makes Linq to SQL easier in grids. 它包含PagedList <T>,使Linq to SQL在网格中更容易。
- It's insanely simple. There's like nothing there and it works well. 非常简单。 那里什么也没有,而且效果很好。
It uses lambdas to generate URLs like:
它使用lambda生成如下网址:
Html.ActionLink<ProductController>(c => c.Edit(p.ProductID),"Edit")
Html.ActionLink <ProductController>(c => c.Edit(p.ProductID),“编辑”)
- Which says "if someone were to call Edit with ProductID as a parameter, what would the URL look like?" The system will then use the lambda along with the already declared routes and figure out the best URL. This is very DRY and lets us change our URLs in one place and have those changes reflected everywhere. 上面写着“如果有人用ProductID作为参数调用Edit,那么URL会是什么样?” 然后,系统将使用lambda以及已经声明的路由,并找出最佳URL。 这是非常干燥的过程,可让我们在一处更改URL,并将这些更改反映到各处。
If you want to run it you need:
如果要运行它,则需要:
- Some flavor of Visual Studio 2008. Visual Studio 2008的某种风格。
SQL Server 2005 Express or some other flavor of SQL
SQL Server 2005 Express或其他一些SQL版本
I known it's cheesy to do demos with Northwind, and we're actively working on more real world, more interesting samples. That said, I'd much rather show off your code, so if you do something cool and Open Source with MVC, let me know. BTW, I've added an ASP.NET MVC category to this blog.
我知道与罗斯文(Northwind)进行演示很轻松,并且我们正在积极研究更多真实世界,更有趣的示例。 就是说,我宁愿炫耀您的代码,所以如果您使用MVC做一些很棒的开源项目,请告诉我。 顺便说一句,我已经在此Blog中添加了ASP.NET MVC类别。
UPDATE #1: PhilHa updated Brad Abrams older (and much more comprehensive) Northwind code to ASP.NET MVC Preview 2, so you can download that much better code below as well.
更新1: PhilHa将Brad Abrams较旧(且更全面)的Northwind代码更新为ASP.NET MVC Preview 2,因此您也可以在下面下载更好的代码。
UPDATE #2: Looks like ASP.NET MVC Preview 2 runs pretty well on Mono. Anyone want to get Northwind up over there as well?
更新#2:看起来ASP.NET MVC Preview 2在Mono上运行得很好。 任何人也想在那边上罗斯文吗?
Download ASP.NET MVC Preview 2 Cheesy Northwind Sample
下载ASP.NET MVC Preview 2俗气的Northwind示例
翻译自: https://www.hanselman.com/blog/aspnet-mvc-cheesy-northwind-sample-code