开发者

Has anyone a great library for the missing MVC 3 html form field helpers?

开发者 https://www.devze.com 2023-03-11 04:23 出处:网络
I\'m building an application using ASP.net MVC 3 and I\'m wondering if anyone knows a great library to fill the gaps of the build-in html form field helpers?

I'm building an application using ASP.net MVC 3 and I'm wondering if anyone knows a great library to fill the gaps of the build-in html form field helpers?

E.g. creating a Textbox is easy:

@Html.EditorFor(model => model.TextboxTest)

But for creating a Dropdown list I have to write:

@Html.DropDownListFor(model => model.DropdownTest, Model.DropdownTestData)

And it should be written li开发者_Go百科ke

@Html.EditorFor(model => model.DropdownTest) 

where DropdownTest is a SelectList.

There is an example solution for this which can be found here.


The same is a list of radiobuttons: It's not included in MVC (at the moment). There is another good solution which can be found here and with this solution I would be able to write

@Html.RadioButtonListFor(model=>model.Item,Model.ItemList)

So there are solutions available but not structured in a library (respectively I didn't found one) and I don't want to copy and paste this solutions together piece by piece (because I cannot update it easily with NuGet e.g.), a whole library would be better but I could not find any.

Please help :)


Take those solutions from the various locations if you want to use them and put them into your own library. And if you want to use NuGet to manage your libraries, you can create your own NuGet repository to hold that library. You can have your NuGet package dependent on the MVC libraries, so all you ever need to pull down is your package and it will include MVC3.


While the user experience for them is quite different, there's no functional difference between a drop down list and a radio button list. Both are "Select one from a list of options" controls. How is a generic EditorFor() going to know which you want in any given scenario? At best, you would have to have something like

    @Html.EditorFor(model => model.DropdownTest, model.DropDownTestData, ListType.DropDownList)

which is not notably better than

    @Html.DropDownListFor(model => model.DropdownTest, Model.DropdownTestData)

Another question to consider is how it would differentiate between editing the choice represented by the dropdown list/radio button list, and editing the list themselves. With a textbox, clearly if you want to edit it, you want to edit its contents, but with a list of options, that's not nearly as certain. Consider the difference in UI between the student and teacher side of a multiple-choice testing app. The teacher wants to create a list of multiple choice answers, and the student wants to pick one of the results, but the data for both is in the form of a list of question/answer pairs.

In short, I think any library that provided this functionality would be just as complicated (if not moreso) than the current methods.

0

精彩评论

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