?
Solved

Hacking the MvcHtmlString

Posted on 2011-10-27
3
Medium Priority
?
433 Views
Last Modified: 2012-05-12
I have an unknown problem setting the default value in a SelectList, when using DropDownListFor() with Razor. SO I was thinking about using jQuery to insert that attribute: Selected='true' at least until I found the source of my problem.

I know the name of the text for the list item, "Name of first pet?"

What's the jQuery I need to grab the list item and insert a new attribute? Or, if you have a better idea to set the default value of a drop down, I'd love to hear it.

Thanks!
0
Comment
Question by:newbieweb
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
effx earned 2000 total points
ID: 37040548
$("select[name=yourlist]").append("<option>newitem</option>");
0
 
LVL 10

Assisted Solution

by:effx
effx earned 2000 total points
ID: 37040555
$("select[name=yourlist]").val("yourvalue");
0
 

Author Closing Comment

by:newbieweb
ID: 37041464
Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question