Custom VisualStudio toolbox items for rendering MVC partials/arbitrary text
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?
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!
精彩评论