为什么我不能用服务器控件在ASP.net MVC? [英] Why can't I use server controls in ASP.net MVC?

查看:175
本文介绍了为什么我不能用服务器控件在ASP.net MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备要负责领导一个小的ASP.net MVC应用程序的开发。这是我第一次创建一个MVC应用程序,所以我很高兴!

我已经仔细阅读文档结束了,我觉得我有多么MVC工作的总体思路。但是,如果我理解正确的话,服务器控件(如GridView控件,例如)不是MVC的一部分。

我的问题是:为什么?在我的开发工作室,我很习惯使用的GridView和MS图表控件,我完全茫然我几乎没有给他们发展的控制。这似乎就像重新开始。

为什么服务器控件不可用? Microsoft如何指望我没有他们的工作?有什么办法?


解决方案

  

我的问题是:为什么?


由于他们大多取决于如ViewState的东西,回发模型这是经典的WebForms模型的一部分​​,并在ASP.NET MVC不复存在。这些服务器端控件依赖于将执行回发到服务器坚持以隐藏域(ViewState中)其状态的事件。在ASP.NET MVC,你不再与事件,如的button1_Click 工作。在ASP.NET MVC你一个型号,一个控制器和视图工作。该控制器负责接收用户请求,查询模型,结果翻译成视图模型,并通过这个视图模式,其职责是根据某种形式来显示它查看。

在ASP.NET MVC也有可能被用来生成视图之间的一些重用的HTML片段HTML佣工。你可能需要在这样的帮手Telerik的ASP.NET MVC套件。他们称他们的控制,但他们什么都没有做与传统的WebForms服务器端控件。他们只是HTML帮手。

基本上经典的WebForms是卷材的漏抽象。微软确实回到时候,他们设计的这个框架是将现有的Windows开发技能,这是越来越多的势头网络。但是,由于网络还是一个新技术,大多数开发者都还不熟悉,他们创造了这个抽象遁形了WWW的工作方式。这些开发商习惯于拖他们的Windows窗体控件下探,上的按钮被产生一些code为他们,他们把他们的数据访问逻辑等双击。这种模式移植到Web应用程序开发感谢的WebForms。 HTTP协议被成功隐藏这个抽象叫做WebForms的后面。例如,你不需要知道HTML,和JavaScript,甚至没有CSS,以创建一个使用的WebForms这实在是太棒了,因为该框架抽象所有这些事情给你一个网站。不幸的是这样做是prevents你不容易利用它开发Web应用程序时,有些人可能需要较低级别的网络技术的全部功能。

什么ASP.NET MVC确实基本上消除这种漏抽象,并把WWW给开发它的目的是通过它的创造者的方式。 ASP.NET MVC相比于传统的WebForms还不够成熟,所以你不能指望找到相同范围内使用控件和小部件,但事情正在慢慢发生变化。

我建议你在ASP.NET MVC从这里开始: http://asp.net/mvc 。来吧,看视频,玩的样本,看看ASP.NET MVC是为你与否。当然,如果遇到一些特殊困难或问题,不要犹豫,回到这里,并要求它。

I'm getting ready to be responsible for leading the development of a small ASP.net MVC application. This is my first time creating an MVC application, so I am excited!

I've carefully read over the documentation and I feel like I have the general idea of how MVC works. However, if I understand correctly, server controls (like GridView, for instance) are not part of MVC.

My question is: Why? At my development shop, I'm so used to using controls like GridView and the MS Chart Controls that I'm almost at a complete loss as to developing without them. It seems almost like starting over.

Why are the server controls unavailable? How does Microsoft expect me to work without them? What are the alternatives?

解决方案

My question is: Why?

Because most of them depend on things like ViewState and the Postback models which are part of the classic WebForms model and no longer exist in ASP.NET MVC. Those server side controls rely on events that will perform postbacks to the server persisting their state in hidden fields (ViewState). In ASP.NET MVC you no longer work with events such as Button1_Click. In ASP.NET MVC you work with a Model, a Controller and View. The Controller is responsible for receiving user requests, querying the Model, translating the results into a view model and passing this view model to the View whose responsibility is to display it under some form.

In ASP.NET MVC there are HTML helpers that could be used to generate some reusable HTML fragments between views. You may take a look for example at the Telerik ASP.NET MVC suite of such helpers. They call them controls but they have nothing to do with classic WebForms server side controls. They are just HTML helpers.

Basically classic WebForms are a leaky abstraction of the web. What Microsoft did back in the time when they designed this framework was to bring existing Windows developer skills to the web which was getting more and more momentum. But since the web was still a new technology that most developers weren't yet familiar with, they created this abstraction to hide away the way that the www works. Those developers were accustomed to drag and dropping controls on their Windows Forms, double clicking on buttons that was generating some code for them in which they put their data access logic and so on. This model was transposed to web application development thanks to WebForms. The HTTP protocol was successfully hidden behind this abstraction called WebForms. For example you don't need to know HTML, nor Javascript, not even CSS in order to create a website using WebForms which is really great because the framework abstracts all those things for you. Unfortunately by doing so it prevents you from easily utilizing the full power of lower level web technologies which some people might need when developing web applications.

What ASP.NET MVC does is basically remove this leaky abstraction and bring the www to the developers the way it was intended to be by its creators. ASP.NET MVC is not mature enough compared to classic WebForms so you cannot expect to find the same range of available controls and widgets but things are slowly shifting.

I would recommend you start here with ASP.NET MVC: http://asp.net/mvc. Go ahead, watch the videos, play around with the samples and see if ASP.NET MVC is for you or not. And of course if you encounter some specific difficulty or question don't hesitate to come back here and ask it.

这篇关于为什么我不能用服务器控件在ASP.net MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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