what's the difference between ASP.NET controls and Html.helpers in ASP.NET MVC?
I'm completely new to C#, asp.net and asp.net mvc. I'm just starting and trying. so here is my question: what's the difference between ASP.NET MVC Html.helpers and ASP.NET Controls? I know they both can be used to create forms in a page, but what's the difference? I mean, I can 开发者_运维问答use ASP.NET Controls in my MVC project, so what's the point of using Html.helpers? It would be great if somebody explains the difference about Html tags too. So,when I should use ASP.NET Controlls, when I should use ASP.NET MVC, and when I should use Html Tags? by the way, I'm using ASP.NET MVC2 in Visual Web Developer 2008 Express. sorry for my bad English thingy!
Big difference, basically an HTML Helper translates to HTML on the Server when it pushes back to the client.
Controls are not available in MVC (you are thinking web forms), but that's a personal preference whether you like this or not. The forms make it easy to create complicated HTML structures, but there's a lot of "Magic" in how they render, MVC gives you complete control.
Once you start using MVC more you will appreciate the flexibility and not miss controls one bit. Plus, a lot of Open Source stuff out there to give you powerful "Helpers"
To add to Mark's answer: Although both ASP.NET controls and HtmlHelpers emit HTML, that's where the similarities end.
ASP.NET controls are very heavy. Many of them maintain their own state across postbacks to give the illusion that you are programming a stateful Windows Forms application. These controls have strange and mangled ID's, add many bytes to your "viewstate" hidden form field, and often have difficult to control markup and CSS styling.
HtmlHelpers render HTML in a customizable way that is lightweight because you control the HTML that is emitted, ideally WITHOUT any state information littering your markup. You control the ID's, the styles, everything. But you lose the automatic state management that the controls give you.
精彩评论