ASP.NET MVC 中简单且一致的表单的解决方案是什么
我们最近聘请了一位设计/ui/辅助功能人员,为我们的 asp.net MVC 应用程序披上一层新鲜的 css 外衣,我设法在他的时间表中加入了整个应用程序中连贯表单的需求。他交付了,我们可以拥有看起来不错且行为正确的表单,
我已经尝试通过列出所需的内容来确定尽可能多的表单 ui,因此我有一个我们可以使用的控件类型“池”;将其视为表单的编辑指南。
但由于我要检查应用程序中的每个表单以使用新设计,因此我想找到一种好方法来做到这一点。理想情况下,一个好的方法是:
- 简洁:如果我可以避免为每个字段输入长的
Html.TextBox(id, value, new with {.all_the_attributes})
,那么手指和眼睛都会感到轻松。 - 详尽:我想确保,如果我们需要文本框上的提示,一切都在那里:javascript、初始化、属性等,只需一次调用即可。我宁愿避免类似
TextBox.AddHint("bla").AddJavascriptForHint("DoIt()").etc
- 万无一失:我的一些同事可能有一个对用户界面一致性的把握不太令人满意。我希望他们尽可能少地感受到痛苦,以使转变变得令人满意。因为我有时也很愚蠢,所以我可能会从故障保护中受益:)
- 可扩展:自动创建一个带有类
this
和that
的文本框很棒,但有时我们希望能够显式地将this
覆盖为thyse
。坦率地说,如果存在的话,这个选项是一个额外的好处,我们总是可以用旧的方式创建罕见的特定输入。
因此,考虑到这一点,我开始探索管理我自己的生成器:我启动了一个 OurForm 类,该类由 HtmlHelper 扩展实例化,并为我们的输入提供一种 DSL。
<%= Html.OurForm.TextBox("id", "value").AddHint("The hint") %>
到目前为止看起来不错。我可以链接表单输入,如果我真的很懒,我什至可以通过一次调用创建整个表单。然而,编码有点无聊,最重要的是我无法在视图中轻松更改它。如果我犯了错误,或者想在设计中提供更多的余地,我必须回到代码中;部分视图会很好,但我在了解如何完成它时遇到问题。
我目前正在研究 Opinionated Html 与 MvcContrib 输入构建器,但我并不总是有适合该表单的模型,所以我并没有真正将这些视为解决方案。有什么帮助或建议吗?你会推荐什么?我应该继续使用我的自定义构建器吗?你用什么?
TL;DR:我可以使用什么来更快地创建表单
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 creating a textbox with classes
this
andthat
is great, but sometimes we want to be able to overridethis
tothyse
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对您的自定义构建器不太了解,但如果它对您有好处,我建议将其与自定义 T4 模板混合。您可以在
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\AddView\CSHTML
中找到用于添加视图的模板
您可以查看一些内置模板并了解如何编写自己的模板。如果您创建模板并放入同一目录中,则在 Visual Studio Designer 中创建视图时可以使用该模板
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