天道酬勤,学无止境

nerddinner

Nerd Dinner validation rules question

In the NerdDinner tutorial, Step 5, mid way down under Complete Edit Action Method Implementations there is a paragraph: The nice thing about our Edit implementation is that neither our Controller class nor our View template has to know anything about the specific validation or business rules being enforced by our Dinner model. We can add additional rules to our model in the future and do not have to make any code changes to our controller or view in order for them to be supported. This provides us with the flexibility to easily evolve our application requirements in the future with a minimum

2021-10-23 03:56:22    分类:问答    validation   controllers   nerddinner

ASP.NET MVC 2 UpdateModel() 不更新内存或数据库中的值(ASP.NET MVC 2 UpdateModel() is not updating values in memory or database)

问题 我是 MVC 的新手,所以我正在学习 NerdDinner 教程,这里。 特别是,我在使用 UpdateModel 方法时遇到了问题,该教程的第 5 部分对此进行了解释。 问题是,当我尝试使用 UpdateModel 方法编辑晚餐对象的值时,这些值不会更新,也不会引发异常。 奇怪的是,我对教程中说明的创建或删除功能没有任何问题。 只有更新功能不起作用。 下面,我包含了我正在使用的控制器代码,以及包含在 aspx 视图文件和 ascx 部分视图文件中的视图标记。 这是我的控制器中的代码,称为 DinnerController.cs: // // GET: /Dinners/Edit/2 [Authorize] public ActionResult Edit(int id) { Dinner dinner = dinnerRepository.GetDinner(id); return View(new DinnerFormViewModel(dinner)); } // // POST: /Dinners/Edit/2 [AcceptVerbs(HttpVerbs.Post), Authorize] public ActionResult Edit(int id, FormCollection formValues) { Dinner dinner =

2021-09-19 17:47:39    分类:技术分享    c#   asp.net-mvc   asp.net-mvc-2   updatemodel   nerddinner

ASP.NET MVC: How to transfer more than one object to View method?

I finished NerdDinner tutorial and now I'm playing a bit with project. Index page shows all upcoming dinners: public ActionResult Index() { var dinners = dinnerRepository.FindUpComingDinners().ToList(); return View(dinners); } In DinnerRepository class I have method FindAllDinners and I would like to add to above Index method number of all dinners, something like this: public ActionResult Index() { var dinners = dinnerRepository.FindUpComingDinners().ToList(); var numberOfAllDinners = dinnerRepository.FindAllDinners().Count(); return View(dinners, numberOfAllDinners); } Of course, this doesn't

2021-08-11 08:20:40    分类:问答    asp.net   asp.net-mvc   object   nerddinner

NerdDinner MVC4 版本 - 他们为什么删除存储库类?(NerdDinner MVC4 version - why did they delete the repository classes?)

问题 我一直在查看 NerdDinner 教程。 我正在阅读使用 LINQ to SQL 和 MVC2 的原始 PDF 教程 (http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf)。 在该教程中,他们实现了数据上下文,然后实现了存储库类以与数据实体进行交互。 我看到该项目已更新为使用 MVC4 和实体框架 (http://nerddinner.codeplex.com),因此我浏览了该代码以查看它们实现了哪些更改。 他们将项目更改为代码优先,每个数据实体都有单独的模型类。 我很惊讶地看到他们完全摆脱了存储库。 我认为通过存储库模式抽象与数据库的通信通常是一种很好的做法......我知道为了简洁起见,教程经常做出糟糕的设计选择,但我想知道为什么已经实现了存储库的教程做出了决定从这个版本中省略它们。 MVC4 或 EF 中是否有使存储库过时/冗余的内容? 回答1 关于在存储库中包装像实体框架这样的高级抽象是否有意义,存在长期争论。 从历史上看,存储库很棒。 这是安全的,有额外的抽象层,只是为了能够以不同的数据提供者,普通的旧之间切换DataSet S,文件,LINQ,等等。 然而,许多 EF 纯粹主义者声称 EF 已经是工作单元和存储库的抽象,数据上下文是工作单元,数据库集是存储库。 他们声称 LINQ

2021-07-28 22:03:16    分类:技术分享    c#   asp.net-mvc-4   entity-framework-5   repository-pattern   nerddinner

ASP.NET MVC:有多少库?(ASP.NET MVC: How many repositories?)

问题 我正在 ASP.NET MVC 中设计一个网站,并且可能对存储库的确切性质有点困惑。 按照 NerdDinner 示例,我的站点应该有一个存储库,可以根据需要提供实体。 但是,我也听说你应该有不同的存储库来处理特定的相关实体集......? 就我的站点而言,将有许多实体(大约 15 个表),但大多数都是相关的。 是否可以/建议拥有一个包含拉/更新/删除等所需的所有方法的存储库,还是应该将它们拆分? 回答1 我为每个数据对象创建一个存储库。 例如,一个简单的图书馆数据库可能包含以下存储库: 作者资料库书库出版商资料库 回答2 我使用一个通用的宝库,它是足够的许多实体。 对于更复杂的一个,我只是用所需的内容扩展此。 两全其美真的。 回答3 在域驱动设计中,有一个规则是存储库是每个聚合根。 你可以在这里读更多关于它的内容。 我读得越多,我就越认为 NerdDinner 经常被视为良好实践的集合,而它绝对不是(请参阅此处的讨论,特别是 NerdDinner 存储库)。 这就是为什么人们经常责怪 Oxite 等其他 MS 示例(这里是: 开发人员会蜂拥而至,赞美它,并盲目地接受它作为福音,因为它来自微软(它已经在路上了)。 可悲的是,任何采用其精神的开发人员都会留下无法维护、无法测试和无法阅读的混乱局面 )。 回答4 如果您使用接受类型的通用存储库,那么我看不出有任何理由使用多个类型。

2021-07-11 06:02:39    分类:技术分享    c#   .net   asp.net-mvc   repository   nerddinner

ASP.NET MVC 2 UpdateModel() is not updating values in memory or database

I am new to MVC, and so am working through the NerdDinner tutorial, here. In particular, I'm running into problems with the use of the UpdateModel method, which is explained in the part five of that tutorial. The problem is, when I try to edit the value of a dinner object using the UpdateModel method, the values do not get updated, and no exceptions are thrown. Oddly, I am not having any trouble with the Create or Delete features that are illustrated in the tutorial. Only the update feature isn't working. Below, I have included the Controller code that I am using, as well as the view markup

2021-06-27 06:59:18    分类:问答    c#   asp.net-mvc   asp.net-mvc-2   updatemodel   nerddinner

ASP.NET MVC: How many repositories?

I am in the process is designing a website in ASP.NET MVC and am perhaps a little confused as to the exact nature of a repository. Following the NerdDinner example, my site should have one repository which serves up the entities as I need them. However, I have also heard that you should have different repositorys that deal with specific sets of related entities....? In the case of my site, there will be a number of entities (around 15 tables) yet the majority are all related. Is it ok / advisable to have one repository that contains all the methods that I'll need for pulling / updating /

2021-06-05 03:47:55    分类:问答    c#   .net   asp.net-mvc   repository   nerddinner

NerdDinner MVC4 version - why did they delete the repository classes?

I've been checking out the NerdDinner tutorials. I was reading through the original PDF tutorial (http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf) that uses LINQ to SQL and MVC2. In that tutorial, they implement a data context and then implement repository classes to interact with the data entities. I saw the project was updated to use MVC4 and Entity Framework (http://nerddinner.codeplex.com) so I browsed through that code to see what changes they'd implemented. They changed the project to be code-first with separate model classes for each data entity. I was surprised to see

2021-06-03 18:22:51    分类:问答    c#   asp.net-mvc-4   entity-framework-5   repository-pattern   nerddinner

Request for Tutorial to add Openid Support to NerdDinner ASP.NET MVC application

I'm looking learn about ASP.NET MVC and OpenId using the ASP.NET MVC NerdDinner tutorial. I would like to replace the Authentication system in NerdDinner to be OpenId only. I've downloaded the latest DotNetOpenAuth libraries but I'm not sure how to put it all together. Can anyone help with a quick step-by-step tutorial? Is this as simple as dropping in the library or are there significant changes needed to the application as well?

2021-04-12 02:10:11    分类:问答    asp.net-mvc   dotnetopenauth   nerddinner

在NerdDinner的ASP.NET MVC中,有效的ModelState.IsValid是什么?(What is ModelState.IsValid valid for in ASP.NET MVC in NerdDinner?)

问题 在Professional ASP.NET MVC 1.0的NerdDinner示例中,有一种方法可以创建一个新的晚宴,如下所示(免费的NerdDinner版本的第89页)。 在那里,它检查ModelState.IsValid是否为true。 似乎正在检查模型是否对数据库有效(也就是说,它会捕获数据类型转换,例如格式无效的日期,而不是业务规则)。 真的吗? 提交表单时,如果日期中有错误,则ModelState.IsValid为false,并且会返回错误,但仅针对该日期,因为从未执行过AddRuleViolations。 如果完全删除对ModelState.IsValid的检查,则将得到所有错误(由于异常),包括无效日期的标记。 然后,为什么根本不检查ModelState.IsValid? 我想念什么吗? // // POST: /Dinners/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Dinner dinner) { if (ModelState.IsValid) { try { dinner.HostedBy = "SomeUser"; dinnerRepository.Add(dinner); dinnerRepository.Save(); return

2021-04-04 09:41:46    分类:技术分享    asp.net-mvc   validation   nerddinner