TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ceci bela
NA
58
12.7k
dropdownlist validation
Nov 3 2014 9:29 AM
On the
create.cshtml
file I need to have a default value selected. I got the default value to work but now it
won't validate
. I googled and someone said that I must use
DropDownListFor instead of
DropDownList. But I can't get the
DropDownListFor to work. Any ideas? Thanks
--controller--
var SelectedState = "New York";
var stateList = new SelectList(db.states, "Name", "Name", SelectedState);
ViewBag.StateOptions = stateList;
--Create.cshtml --
@Html.LabelFor(model => model.State)
@Html.DropDownList("StateOptions", String.Empty) <=== This works but won't validate.
//@@Html.DropDownListFor(model => model.State,new SelectList(ViewBag.StateOptions,"Id","Name"), "Pick State") <== Tried this too but no luck. @
@Html.ValidationMessageFor(model => model.State)
Output
https://www.dropbox.com/s/xy97ju2guop9ux2/stateDropdown.png?dl=0
Reply
Answers (
2
)
payment gateway india for website
Asp.net WebPart Drag Drop not working in IE 11, IE 10, IE 9