I'm trying to save the selected item from my dropdownlist menu in a MSSQL table where the menu is populated from another MSSQL table. But whenever I run my project I get compilation error,
CS1502: The best overloaded method match for 'System.Web.Mvc.SelectList.SelectList(System.Collections.IEnumerable, string, string)' has some invalid arguments
Here are my codes,
View
@using (Html.BeginForm("BoxManager", "Home"))
{
@Html.ValidationSummary(true)
<div class="editor-label">
<strong>Full Name</strong>
</div>
<div class="editor-field">
@Html.DropDownListFor(a => a.Boxes.clientname, new SelectList(Model.Clients, "fullname", "fullname"))
@Html.ValidationMessageFor(a => a.Boxes.clientname)
</div>
<p><input type="submit" class="btn btn-info" value="Add" /></p>
}
Model
public class BoxManagement
{
public BoxInfo Boxes { get; set; }
public IEnumerable<BoxInfo> BoxCollection { get; set; }
public ClientInfo Clients { get; set; }
}
Controller
public ActionResult BoxManager()
{
return View();
}
[HttpPost]
public ActionResult BoxManager(BoxManagement BoxModel)
{
if (ModelState.IsValid)
{
var AddBox = BoxModel.Boxes;
db.BoxInfoes.Add(AddBox);
db.SaveChanges();
return RedirectToAction("BoxPanel");
}
return View(BoxModel.Boxes);
}
Am I doing something wrong here? How can I save the dropdownlist selected item in my BoxInfo model? Need this help badly. Tnx.
ModelStateis not valid then it should bereturn View(BoxModel);and you would need to reassign the value ofBoxCollection