Error:
There is no ViewData item of type 'IEnumerable' that has the key 'JobCodeType'.
Controller:
- public ActionResult Index()
- {
- List
items = new List (); - items.Add(new SelectListItem { Text = "Community", Value = "0" });
- items.Add(new SelectListItem { Text = "In-House", Value = "1", Selected = true });
- items.Add(new SelectListItem { Text = "Vacation", Value = "2" });
- items.Add(new SelectListItem { Text = "Sick", Value = "3" });
- items.Add(new SelectListItem { Text = "Absent", Value = "4" });
- items.Add(new SelectListItem { Text = "Not Scheduled", Value = "5" });
- if (ViewData["JobCodeType"] == null)
- {
- ViewData["JobCodeType"] = items;
- }
- return View();
- }
- [HttpPost]
- public ActionResult ShowDDL(FormCollection obj)
- {
- string str = obj["JobCodeType"];
- ViewBag.D = obj["JobCodeType"];
- return View("Index");
- }
Index.cshtml
- @{
- Layout = null;
- }
- "viewport" content="width=device-width" />
Index1 - @using (Html.BeginForm("ShowDDL", "Home", FormMethod.Post))
- {
- @Html.DropDownList("JobCodeType")
- "Submit1" type="submit" value="submit" />
@ViewBag.D
- }
Please help....................
Anoop Kumar SharmaPosted May 4, 2019, 1:35 AM
Laxmidhar SahooPosted May 4, 2019, 4:18 AM
Bryian TanPosted May 3, 2019, 11:26 PM
Nilesh SawardekarPosted May 3, 2019, 10:04 AM
Pravinkumar BirajdarPosted May 3, 2019, 9:24 AM
Nilesh SawardekarPosted May 2, 2019, 9:05 AM