views:

874

answers:

2

Hi, I have looked around on the Internet trying to answer this question. It seems to be kind of complicated though! Seems to come up with all sorts of different topics such as the HtmlHelper and other stuff.

Basically. How can you use custom controls with MVC? In a way that avoids doing anything that is frowned upon.

Also, Is it true that with MVC you have to put some simple logic IN THE PAGE? Isn't that what we should be getting away from?

Update: So, Seems you cannot use controls which depend on anything which MVC does away with, such as the postback events and viewstate. Can you make your own then? A control which does only rendering of course.

+1  A: 

With respect to the second question, the page is exactly where view logic should go. Any other logic should be in your controllers or models.

I'm not sure what you mean by custom controls. You can have ViewUserControls that are rendered via partials to reuse view code. If you are talking about 3rd part controls built for webforms, it's likely they won't work -- at least for awhile. If you absolutely must have them, though, there are ways to mix MVC with traditional webforms in the same site.

tvanfosson
+2  A: 

Can you use ASP.NET controls? Maybe. If the control does not use ViewState or postback events, it will probably work. For example, the LoginView control works just fine. Telerik supports ASP.NET MVC with some of their controls. On the other hand, if the control needs either ViewState or postbacks, then it just isn't going to work. Controls with data binding aren't ideal, since you typically have to use code behind him up. But they will work, if you add code behind.

On the other hand, controls with no knowledge of ASP.NET (such as the jQuery UI controls) work very well.

No, you don't have to put your logic in the page. You just don't put it on a code behind page, either. Instead, use helper methods.

Craig Stuntz