0
votes

So I have a Edit view with a partial view. In this partial view I have a selectlist (or dropdownlist) which values come from a ViewBag. In the control I include the selected value but it just does'nt work.

public ActionResult Edit(int id = 0)
    {
        Customer c = db.Customer.Find(id);

        ViewBag.CustomerGlobalQuality = new SelectList(db.GlobalQuality, "Id", "Quality", c.Skill.GlobalQuality);            
        return View(c);
    }

and in the PARTIAL VIEW I have:

 @Html.DropDownList("CustomerGlobalQuality")
 @Html.ValidationMessageFor(model => model.Skill.GlobalQuality)

what did I miss? It usually works with normal views, so why not with a partial?

1
what do you mean by it never works? Any exception? - ramiramilu
no selected value in the selectlist, no exception - Natalia

1 Answers

0
votes

if your logic doesn't need partial view, do not include it in this case. Use those lines of code inside your edit chtml view. In your case debug it and see what are you realy sending to drop down list. I see that you included dropdown list dana in edit view. If you use partial view you must pass object to that view in controler.

public ActionResult PartialDDLData() {

    ViewBag.CustomerGlobalQuality = new SelectList(db.GlobalQuality, "Id", "Quality", c.Skill.GlobalQuality);            
    return Partial("_nameOfView",ViewBag.CustomerGlobalQuality);
}

and make sure your partial view is accessible in shared or controller view folder.