Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 21, 2012 05:13 PM by ricka6
Feb 19, 2012 11:37 PM|LINK
I’ve found tons of info on dropdown list but still seem to have problems with mine... When my user selects a value from the dropdown list then click on save. Everything
else but the selected value from the dropdown list show in the resulting view. How can I fix this?
Here’s my view:
Here’s my controller:
public ActionResult Create()
ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "Name");
public ActionResult Create(CourseProgress courseprogress)
ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "Name", courseprogress.Course.CourseId);
Thanks for any help
Feb 19, 2012 11:49 PM|LINK
try to use
@Html.DropDownListFor(model => model.SelectedId, (SelectList)ViewBag.CourseId)
where you need to add selectedId as a property in your module(CourseProgress), and you can access the value of it from your Create method with HTTPOST attribute.
Feb 21, 2012 03:25 AM|LINK
I tried all three of these and none worked.
<td>Course @Html.DropDownListFor(model => model.SelectidId, (SelectList)ViewBag .CourseId)</td>
<td>Course @Html.DropDownListFor(model => model.CourseId, (SelectList)ViewBag .CourseId)</td>
<td>Course @Html.DropDownListFor(model => model.Course.CourseId , (SelectList)ViewBag .CourseId)</td>
Perhaps it’s because I’m using complex types like these:
<td>Student @Html.EditorFor(model => model.Student.Name)</td>
<td>Teacher @Html.DropDownList("TeacherId", String.Empty)</td>
<td>Start Date @Html.EditorFor(model => model.PdfReport.StartDate)</td>
I’m still researching but so far nothing I found works for me.
Feb 21, 2012 04:00 AM|LINK
you should use @Html.DropDownListFor.
what is the property name and type in CourseProgress that the dropdown is supoosed to bind to?
Feb 21, 2012 06:21 AM|LINK
Feb 21, 2012 05:13 PM|LINK
Working with the DropDownList Box and jQuery and My blog
Cascading DropDownList in ASP.Net MVC