6

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 like

@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 :)

Community
  • 1
  • 1
Marc
  • 6,749
  • 9
  • 47
  • 78
  • 1
    If `@Html.EditorFor(model => model.DropdownTest)` had to render a dropdownlist where `DropdownTest` is a SelectList, what property would this dropdownlist bind to? There is a reason why the DropDownListFor helper takes two arguments: a list and a property to use for the model binding and provide default value for this list. So I would be totally against the existence of such helper as it wouldn't make sense. As far as the `RadioButtonListFor` helper is concerned, it is a couple of lines of code to implement such helper. It will hopefully be included in the vNext. – Darin Dimitrov Jun 17 '11 at 10:09

2 Answers2

2

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.

Charles Boyung
  • 2,464
  • 1
  • 21
  • 31
  • 1
    Yes but then **I** am the one who has to update the library - I thought this could do anyone else :) If there is really no such library available I will start an open source project for it. – Marc Jun 08 '11 at 14:15
1

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.

Bobson
  • 13,498
  • 5
  • 55
  • 80
  • Maybe you are right but I'm searching for a way to use Html.EditorFor for every Input Control. The switch between Dropdown or Radio could be made by an UIHint Attribute in the ViewModel. And there you have to tell the UIHint where to load the list - thats possible but difficult. I want to seperate the view and the decision which editor is used for a single element as much as possible. That is complicated, I totally agree, but that's why I don't want to code it by myself... :-) – Marc Jun 17 '11 at 15:50