i have a dropdown as seen below, trying to pass my id to controller but always comes as 0
<div class="form-group">
@Html.LabelFor(model => model.SagsTypersId, "SagsTypeId1", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("SagsTypeId1", null, htmlAttributes: new {
@class = "selectpicker",
data_show_subtext = "true",
data_live_search = "true"
})
@Html.ValidationMessageFor(model => model.SagsTypersId, "", new { @class = "text-danger" })
</div>
</div>
heres is my controller Get.
public ActionResult Create()
{
ViewBag.SagsTypeId1 = new SelectList(db.SagsTypers, "Id", "SagsTyper");
return View();
}
here is controller Post
public ActionResult Create(Sag sag)
{
if (ModelState.IsValid)
{
db.Sags.Add(sag);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(sag);
}
to sum it up, my issue is that the Sags.SagsTypersId is 0 when trying to submit. Can't seem to locate the error.
Best regards Johnny.