'Is getting dropdown in MVC to bind to model
I have gone through many other versions of this question, but my attempt is just not working. I have a notice model.
public class Notice
{
[Key]
public int NoticeId { get; set; }
public string UserId { get; set; }
public string NoticeTitle { get; set; }
public bool Public { get; set; }
public NoticeType Type { get; set; }
}
with a NoticeType Table
public class NoticeType
{
[Key]
public int NoticeTypeId { get; set; }
public string Type { get; set; }
}
I then populate the select list in my Get.
public ActionResult Create()
{
List<NoticeType> _noticeTypes = db.NoticeTypes.ToList();
SelectList noticeTypes = new SelectList(_noticeTypes, "NoticeTypeId", "Type");
ViewBag.NoticeTypes = noticeTypes;
return View();
}
And the dropdown populates with my table data.
@Html.DropDownListFor(model => model.Type, ViewBag.NoticeTypes as SelectList, new { @class = "form-control" })
But, the type value does not get passed to my Create post.
Please, can someone explain why.
Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
