开发者

What solution for easy and consistent forms in asp.net mvc

We've recently hired a design/ui/accessibility guy to give our asp.net MVC app a coat of fresh css love, and i managed to slip in his timetable the need for coherent forms throughout the app. He delivered and we can have forms that look good and behave correctly

I already tried to pin down as much form ui as i could by listing what was needed, so i have a "pool" of control types that we can use; think of it as editorial guidelines for forms.

But since i'm going to go over every form in the app to use the new design, i'd like to find a good way to do it. Ideally, a good way would be:

  • concise: if i could avoid typing long Html.TextBox(id, value, new with {.all_the_attributes}) for each field, it would be an ease on the fingers and the eyes.
  • exhaustive: i want to make sure that if we need a hint on a textbox, everything is there: javascript, initialization, attribute, etc in just one call. I'd prefer to avoid something like TextBox.AddHint("bla").AddJavascriptForHint("DoIt()").etc
  • foolproof: some of my colleagues may have a less than satisfactory grasp of coherence in the ui. As much as possible i'd like for them to feel as little pain as possible to make the switch desirable. And since i'm also foolish sometimes i might as well benefit from the failsafes :)
  • extensible: automagically开发者_如何学Go creating a textbox with classes this and that is great, but sometimes we want to be able to override this to thyse explicitly. Frankly, this option is a bonus if present, we can always create the rare specific inputs the old way.

So with this in mind i started exploring this managing my own generator: I started a OurForm class that is instantiated by an HtmlHelper extension, and that offers a kind of DSL for our inputs.

<%= Html.OurForm.TextBox("id", "value").AddHint("The hint") %>

It's looking good so far. I can chain form inputs, and if i'm getting really lazy i can even create whole forms with one call. However, it's a bit boring to code, and above all i can't change it easily in the view. If i made a mistake, or would like to offer a bit more leeway in the design, i have to get back in the code; a partial view would be nice, but i have problems seeing how it would be done.

i'm currently looking into Opinionated Html with MvcContrib Input Builders, but i don't always have a model that fits the form, so i'm not really seeing these as solutions... Any help or advice? What would you recommend? Should i continue using my custom builder? What do you use?

TL;DR: what can i use to be able to create forms more quickly


Don't know much about your custom builder but if its going good for you, i would recommend mingling it with custom T4 templates. you can find these templates for adding views in C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\AddView\CSHTML
There are some built in templates that you can see and find out how to write your own. If you create you template and put in the same directory it will be available to you when creating a view in visual studio designer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜