0

I am trying to add a drop down select element to my .net page, but I need it to be black so I can populat it with a json list I have with jQuery. Right now, my view has this:

@Html.DropDownList("Language", new SelectList(" "), "name = 'Laguange'", new { @class = "Language-List field form-group form-control" })

This 'works', but it seems to be confusing some stuff when I try to submit the form it is in. The value I select from it is never seen by the model, as it keeps triggering my [Required] validation helper.

Does anyone know How to add this without the new SelectList(" ") attribute?

1 Answer 1

1

I would suggest it's because youre using the name attribute in the wrong place. Try this:

 @Html.DropDownList("Language", new SelectList(" "), new {Name="Language", @class = "Language-List field form-group form-control" })

Notice the capital Name

Although as they are the same, you can just leave it out:

 @Html.DropDownList("Language", new SelectList(" "), new {@class = "Language-List field form-group form-control" })
Sign up to request clarification or add additional context in comments.

1 Comment

You mention that you're using jQuery, you should post that as well. As the .DropDownList() helper doesn't tie to a model, are you saying it 'triggers' the required attribute in your server side action when you post the form?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.