views:

31

answers:

2

Our development team has a number of semi-technical users that act as intermediaries between our developers and domain experts. One of their tasks is building forms using a very clumsy, antiquated system that makes their job much harder than it should be.

I'd quite like to create toolbox controls similar to the standard HTML controls that simply render an MVC partial e.g.

<% Html.RenderPartial("UserProfilePartial", ViewModel.UserProfile); %>

but presented as a friendly toolbox item with an icon. This way our developers can create reusable form elements that they can simply drag and drop around in the design view. While this may sound like anathema to most developers, they're quite excited about the possibility.

Creating a custom server control does not appear to be the right approach, as it always insists upon adding a register statement to the head of the view, and it also seems to insist upon rendering controls with the <cc{0}...> prefix.

How can I create a Toolbox control that just renders arbitrary markup?

+2  A: 

Take a look here and here.

Darin Dimitrov
That's certainly helpful, but not quite what I'm after. I know it sounds trivial, but from a non-programmer's perspective there's a big difference between a code snippet and control with an icon and a friendly label.
Bayard Randel
+1  A: 

I blogged a while ago about how to write declarative ASP.NET controls for use with ASP.NET MVC. If you want a design-view experience then controls are the only option since that's the only code you get to run in the VS designer.

Having said that, Darin's two links are definitely the most MVC-friendly way to go. Some folks don't like seeing controls in their MVC view pages. Then again, it's strictly a matter of opinion, it's neither right nor wrong, nor is it even a bad practice. So if it fits your team's needs, go for it!

Eilon
Thank you for your reply Eilon! As far as I can tell however, MVC-futures provides a fixed set of controls (textbox, repeater etc.) Is it possible to define your own controls, instead of just changing the behaviour of the Future's controls, or am I misinterpreting your blog post?
Bayard Randel
@Bayard The controls in MVC Futures are just samples, so you are free to copy the code and modify them to your own needs or add new ones. I'm the dev lead for the ASP.NET MVC team at Microsoft, so I was just blogging about a neat sample I added to MVC Futures :)
Eilon