views:

469

answers:

4

In ASP.NET webforms we have server components, that can be encapsulated into an external assembly and shipped as product. In ASP.NET MVC we don't have server components, so what's the best option for external components?

Looking around it seems like the only possible option is making an Html helper method that returns a bunch of html + js that manipulates things. And if the component needs some logic, a http module that add some new routes and a controller defined in the same external assembly to handle the ajax calls.

Otherwise RenderPartial only returns a view... but a view is a real file, so difficult to encapsulate in an external assembly unless it's added as resource file and then retrieved using a path provider that looks into the resource file instead of a real location on the disk.

Or are there any other options I'm not considering?

Thx Simo

A: 

ASP.NET MVC fully supports custom controls and user controls in addition to Html helpers. Nothing stops you from developing a custom control (for a fancy grid, let's say), encapsulating it in an assembly, and shipping it. Am I missing the point of the question?

James D
Yes, I think you're sort of missing the point of the question. Many ASP.NET custom controls (including some from Microsoft) depend wholly or partially on client ViewState and postbacks, neither of which are available in ASP.NET MVC. ASP.NET controls which use neither worked fine in MVC.
Craig Stuntz
+1  A: 

Nothing stops you from developing a custom control (for a fancy grid, let's say), encapsulating it in an assembly, and shipping it

But this will work only for the first rendering: what if I want to have the grid sortable/paging-able/editable and so on?

CodeClimber
A: 

If you want to do, say, sorting and paging, one way is via AJAX. Telerik has a demo of this with their grid.

Craig Stuntz
+1  A: 

Since the server-side logic is completely decoupled from the client side logic it's not really useful to make a both server- and clientside component for Asp.Net MVC. You can better make pure Html/Javascript components and that are usable on multiple platforms (Ruby on rails, php, python, java) and with a tutorial how to integrate them on several platforms. The platform where you develop for is not asp.net mvc, but web browsers in general! A good source of inspiration is the Ext JS Framework

Paco