Server Controls and MVC

I've been lead to believe, without research, that server controls are forfeited in the MVC model. I am both very curious to know if this is true, and if so, how would one achieve something equivalent to a Repeater control, or any other view whose exact structure depends on the content of the model?


I disagree, Yuriy, that controls aren't useful. A set of data-bound MVC controls, easily bound to viewdata, sans obstinate ID rewriting, with no reliance on nasty viewstate or postback gunk and complete control over templating (defaulting to sensible markup), would be an excellent addition to the MVC framework. Controls are a very powerful and useful concept which can significantly increase development time, and shouldn't be discarded solely because they carry some emotional baggage from the ugly old webforms days! :)

ASP.NET MVC does not support ViewState nor postbacks so all controls relying on that will not work. The repeater control is one of the few that doesn't need it so it does work though.

The mvc equivalent of control is the HtmlHelper classes which generate html for you. The collection of htmlhelpers is quite large but you will not automatically find equivalents to the regular webforms controls because of the different nature of webforms and mvc.

MVCContrib is the contrib project for mvc so you will also find more htmlhelpers there

It is also quite easy to roll your own htmlhelper methods

A good starting point for ASP.NET MVC is found here

Correct, rails-like MVC doesn't fully support server-side controls with all their messy viewstates etc... You CAN use some of them but shouldn't really even bother. You can reuse UI portions by utilizing view components and maybe use some nice client-side widgets from jQuery UI or Yahoo UI to build rich grids, etc... As for the repeater... "foreach" is your friend :)

As far as I've understood, you don't need server controls. Instead, you would build a model class, and then a view class that would be responsible for displaying the data from that model. Excerpt from MSDN:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View. The view manages the display of information.

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

That's incorrect, you can still use Server Controls. The engine that parses/ processes the views is still the same ASP.NET runtime that Web Forms uses.

An example using the Repeater control.

I suppose that there will be some kind of smart helper methods, like html.textbox or similar, and they will draw table/grid for example, based on given object collection. You can pack your html helper inside asp custom control and use it in any mvc app... Some think like regular server side controls, but without viewstate, events, and all other pagelifecycle-dependent stuff.

Need Your Help

Android button background image in java code

java android imagebutton

I have 45 buttons which i have created by loop in java code. Now i need to set and change the background image depending on the user interaction and also need resize the image also depending on the

PHP Extract zip string

php zip zlib

I have an integration project with ERP system that return me a list of invoices compressed with zip as binary string: