如果一个MVC控制器和视图有一个1对1的关系? [英] Should an MVC Controller and View have a 1 to 1 relationship?

查看:142
本文介绍了如果一个MVC控制器和视图有一个1对1的关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用asp.NET MVC建立一个网站的内容管理系统的部分,当它似乎打破了这样的站点地图作品有重建所有我的看法是部分景色的的可憎的工作。

例如,我的FAQAdminController有意见:指数AddFAQ,EditFAQ,ConfirmDeleteFAQ而这些有可能成为局部视图

有人告诉我,每个控制器应该有一个单一的视图,并在将要显示应该被实现为局部视图页面内容结束所有其他形式的或行动。

我发布之前已经确认并没有文件,文章,维基百科或SO问题,给我一个直接的答案,是否或没有每个控制器多个浏览次数更是打破了MVC模式。

严格地说,应在MVC控制器和视图有一个1对1的关系?


解决方案

  

有人告诉我,每个控制器应该有一个单一的视图,并在将要显示应该被实现为局部视图页面内容结束所有其他形式的或行动。


这是胡说八道。


  

严格地说,应在MVC控制器和视图有一个1对1的关系?


绝对不是。在逻辑一致的方式设计应用程序。

一个控制器通常处理许多行动并返回很多不同的意见。你可以考虑有一个FAQController渲染所有的意见,既为用户和管理员。

I am currently using asp.NET MVC to build a Content Management System parts of a website and have the odious job of recreating all of my Views as Partial Views as it appears to be breaking the way the site map works.

For example, my FAQAdminController has the Views: Index, AddFAQ, EditFAQ, ConfirmDeleteFAQ and these have to become partial views.

I have been told that each Controller should have a single View and all other forms or actions that end in page content to be displayed should be implemented as Partial Views.

I have checked before posting and no documentation, articles, wikis or SO questions give me a straight answer as to whether or not having multiple Views per Controller is breaking the MVC model.

Strictly, should an MVC Controller and View have a 1 to 1 relationship?

解决方案

I have been told that each Controller should have a single View and all other forms or actions that end in page content to be displayed should be implemented as Partial Views.

That's nonsense.

Strictly, should an MVC Controller and View have a 1 to 1 relationship?

Absolutely not. Design your application in a logical and consistent way.

A controller usually handles many actions and returns many different views. You could consider having a FAQController to render all the views, for both user and admin.

这篇关于如果一个MVC控制器和视图有一个1对1的关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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