asp.net-mvchtml.dropdownlistforselected

Html.Dropdownlist selected value not working


In my project, Html.DropdownList could not display its selected value.It displays the initial value of the list.My controller and view codes are given below:

Controller:

public ActionResult Edit(int id = 0)
    {
        PERMISSION permission = permissionManager.Find(id);
        ViewBag.MODULE_ID = new SelectList(moduleManager.GetAll(), "ID", "TITLE",permission.MODULE_ID);
        return View(permission);
    }

View :

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

But if I write :

@Html.DropDownList("MODULE_ID", String.Empty)

It works fine.but I have to add the class="form-control".What should be solution?
UPDATE:
I have changed the ViewBag name from ViewBag.MODULE_ID to ViewBag.ModuleList. It may conflicts with the name of the dropdownlist. and now It works fine.


Solution

  • I have changed the ViewBag name from ViewBag.MODULE_ID to ViewBag.ModuleList. It may conflicts with the name of the dropdownlist. and now It works fine.