0

in my action method I used

ViewBag.type = new SelectList(
   db.UserDetails.AsEnumerable().GroupBy(x => x.type).Select(x => x.First()),
   "type",
   "type",
   user.type);

in my view I used

@Html.DropDownListFor(
   m => m.type,
   (IEnumerable<SelectListItem>)ViewBag.type,
   new { @class = "form-control" })

don't know whats wrong why not showing the selected item on load

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
Monika
  • 73
  • 1
  • 4

1 Answers1

1

DropDownListFor Not Selecting Value

the correct answer I found on this link

The reason is you are using ViewBag's name the same as the model's property.

Community
  • 1
  • 1
Monika
  • 73
  • 1
  • 4
  • 1
    Not only that but using the last parameter of the `SelectList` constructor (`user.type`) is just pointless and you can remove it. –  May 05 '15 at 11:00
  • Your going to need to ask a new question with a bit more detail than just that. I'm not sure what you mean by _"add js file in popup partial view"_? You never add scripts to a partial view, only to the main view or layout. –  May 06 '15 at 07:29
  • actually i want to bind cascading dropdownlist in popup partial view, when popup load show only first dropdownlist and hide the second dropdownlist when user select the first dropdown then according to that second dropdown show. So for that i want add javascript file to hide and show in popup partial view. – Monika May 06 '15 at 12:31
  • [This answer](http://stackoverflow.com/questions/28627421/better-way-to-load-2-dropdown-in-mvc/28640420#28640420) will help you get started, but if you have any problems you need to ask a NEW question –  May 06 '15 at 12:34