电网建设中的MVC控制器 [英] Building Grid in MVC Controller

查看:120
本文介绍了电网建设中的MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模式/设计问题。它是认为不好的做法,建立一个asp MVC应用程序?

I have a pattern/design question. Is it considered bad practice to build a grid in the controller of an asp mvc application?

有关情况,也有jqGrid的,可以在其中以建立网格填充特定型号的服务器端适配器。这包括构建列,包括列选项(宽度,sortindex,exitable等)。结果
我通常会看在网格为presentation模板/脚手架应该驻留在视图的建设。我想一般preFER预留网格设置code的观点,只是有控制器将数据传递到视图。我在错误的思维方式呢?

For instance, there are server side adapters for jqgrid in which you can populate a specific model in order to build the grid. This includes constructing the columns, including column options (width, sortindex, exitable, etc).
I typically would look at the construction of the grid as presentation templating / scaffolding that should reside in the view. I would generally prefer to reserve the grid setup code to the view and just have the controller deliver the data to the view. Am I thinking of this in the wrong way?

感谢您的任何想法。

推荐答案

问题是如何深在视图中使用的元素需要由视图中指​​定。只是一个例子。您可以使用<选择>在视图元素,它会看起来像在不同的网络浏览器略有不同。基座元件,其可以在页面上可能是更复杂的。刚刚尝试使用<输入类型=日期>从HTML5 (见的此处并尝试演示谷歌浏览器)。你会看到内置的日期选择器而你没有明确在您的视图渲染许多元素(由presentation模板)。

The problem is how deep the elements used in the view need be specified by the view. Just an example. You can use <select> element in the view and it will looks like a little different in different web browsers. The base elements which you could you on the page could be more complex. Just try to use <input type="date"> from HTML5 (see here and try the demo in Google Chrome). You will see many elements of built-in datepicker which you don't explicitly render in your view (by presentation templating).

我的意思是,你可以在视图中使用一些控制,你应该跨preT为你应该不会使基本元素。在使用jqGrid的情况下,你应该只指定一个空的&LT;表&gt;对地方 id元素属性你想拥有的电网。您将没有明确承租人在视图中格的元素。相反的,你可以填写基本电网元件/设置属性。该网格将填充数据对于JavaScript的code的,你包括在页面上,并从相应的控制器动作,你应该提供的jqGrid返回的数据。

What I mean is that you can use some controls in the view which you should interpret as base elements which you should don't render. In case of usage jqGrid you should just specify an empty <table> element with an id attribute on the place where you want to have the grid. You will be not explicitly renter the elements of the grid in the view. Instead of that you can fill/set "properties" of the base grid element. The grid will be filled with the data with respect of JavaScript code which you include on the page and the data returned from the corresponding controller action which you should provide for jqGrid.

我同意这样的模式匹配与MVC模式并不理想,但我个人是不是教条以下一些机型。

I agree that such schema matches not ideal with MVC model, but I personally be not for dogmatic following some models.

唯一真正的设计问题,我在上面架构描述看到在JavaScript中code定义电网的部分地区 colModel 主要由现有的限制。在使用动态系统的情况下,它可能是更有趣的提供 colModel 属性与数据网格在一起。 jqGrid的不提供直接的方式来做到这一点,但我贴了一些答案,描述一个人如何能不做出相应的实施。其主要思想从使用由 setColProp showCol hideCol setCaption setLabel setColWidth 和其他的内部 beforeProcessing 。它允许编写通用的JavaScript code显示的任何通用的网格并加载来自服务器的网格的所有属性。我建议您阅读答案提供了一些重要的code碎片和的the回答

The only real design problem which I see in described above schema are existing restrictions in defining some parts of the grid colModel mostly in JavaScript code. In case of usage dynamic system it could be more interesting to provide the colModel properties together with the data for the grid. jqGrid don't provide direct way to do this, but I posted some answers which describe how one can do make the corresponding implementation. The main idea consist from the usage setColProp, showCol, hideCol, setCaption, setLabel, setColWidth and other inside of beforeProcessing. It allows to write generic JavaScript code to display any generic grid and to load all properties of the grid from the server. I would recommend you to read the answer which provides some important code fragments and the answer.

而不是创造了许多隐藏的列网格,并显示出有必要时可以使用 addColumn 方法,仍处于测试阶段,但它的作品不够好,这code口发表这里(见演示相应的例子子目录中)。

Instead of creating the grid with many hidden columns and showing there if required one can use addColumn method with is still in beta phase, but it works good enough, which code I published here (see the corresponding examples in demos subdirectory).

这篇关于电网建设中的MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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