tags:

views:

232

answers:

2

hi,

the more i dig into MVC the more i love it and think how was I working with Web Forms :)

but somethings are really confusing like in in Web forms if i wanted to encapsulate a controls, let us say a Combo Box, then i would create a user control and add this Combo Box to it and declare Properties, then i can drop it on any page and if i change the user control the change applies to all instances in the site, pretty easy in web forms.

now in MVC i have learned that you can create Extra Helpers by Extension Methods and it is really cool, but my aim is that i want it to be Ajaxified.

here is what i want:

  • i want it to emulate Web Forms like Text Property, Selected Value, etc...
  • i will be using jquery for cool effects like highlight an Item on mouse hover, so i want a way to include the scripting with this HTML Helper so i wont have to write it on a View or master page for each Combo Box I add, in other words like for Example Telerik Controls or any Web Forms Server Control.

another Question is are HTML Helpers rendered on Server ? or they are pure HTML and there is no Server Processing like Server Controls ?

Note: i know that MVC already has a list HTML Helper, but i brought this as an example.

thanks in advanced.

+1  A: 

The HtmlHelper Extension Methods are executed within the View on the Server. The resulting HTML that they generate is included within the page that is send to the Browser.

You can't create a traditional ASP.NET WebForms Server Control using an HtmlHelper Extension Method the way that you describe, "emulate Web Forms like Text Property, Selected Value, etc..." If you were able to implement such a thing using ASP.NET MVC, then you should probably just be using ASP.NET WebForms for your project in the first place.

I really recommend picking up a copy of "Pro ASP.NET MVC 1.0". This book was written by Rob Conery, Scott Hanselman, Phil Haack and Scott Guthrie, and is full of a ton of explanations of "what to do and why" when building apps/sites using ASP.NET MVC; along with direct comparisons to the differences between ASP.NET WebForms and ASP.NET MVC. Also, the first chapter of the book is a complete tutorial on building a fully functional application using ASP.NET MVC instead of the traditional "Hello World" example that every other book demonstrates.

Chris Pietschmann
thanks for your reply man,i did not want to build something like web form exactly, i just want to cut down some repetitive jobs.like when you create HTML Helper you are doing that and saving your self time, but my question is how to inject it's JavaScript automatically, like for example the edit box here in stack over flow ?and yeah i have the book, and it is a great book, one of the reasons that let me get into MVC seriously !
+1  A: 

Have you looked at the AjaxHelper class and it's extensions? That seems like what you're looking for. You could look at the source for the AjaxExtensions.cs file and then create your own AjaxHelper extensions following the same pattern.

Yes, HtmlHelper (and AjaxHelper) functions output Html strings via C# code executed on the server.

Dennis Palmer