1

I am making some changes to already existing ASP.NET MVC 1 app where there is a form with a dropdown list that has all 50 states hard coded into the HTML. After filling out the form the user can later go back and edit their information. I want to make it so that on the edit screen the value that is already in the DB gets the "selected" attribute for the state. The only way I can think to do this is to build the html on the server and send it down to the view, is there a better practice?

1 Answer 1

2

No, View is the only place where you should generate the markup.

My suggestion is to write a JavaScript snippet like this:

 $(function(){ 
     $('#dropDownId').val(@Model.SelectedValue);
 });

It's effective, easy, maintainable, and of course, fast.

Sign up to request clarification or add additional context in comments.

Comments

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.