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 SharmaRank #127 · 17.4K reputationPosted May 3, 2019, 9:35 PM EDT
Nilesh SawardekarRank #648 · 3.7K reputationPosted May 2, 2019, 5:05 AM EDT
Pravinkumar BirajdarRank #2,222 · 632 reputationPosted May 3, 2019, 5:24 AM EDT
Nilesh SawardekarRank #648 · 3.7K reputationPosted May 3, 2019, 6:04 AM EDT
Bryian TanRank #396 · 6.3K reputationPosted May 3, 2019, 7:26 PM EDT
Laxmidhar SahooRank #383 · 6.6K reputationPosted May 4, 2019, 12:18 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts