TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pravinkumar Birajdar
1.2k
584
109.5k
ASP.NET MVC Error
May 2 2019 6:48 AM
Error:
There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'JobCodeType'.
Controller:
public
ActionResult Index()
{
List<SelectListItem> items =
new
List<SelectListItem>();
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
;
}
<!DOCTYPE html>
<html>
<head>
<meta name=
"viewport"
content=
"width=device-width"
/>
<title>Index1</title>
</head>
<body>
<div>
@using (Html.BeginForm(
"ShowDDL"
,
"Home"
, FormMethod.Post))
{
@Html.DropDownList(
"JobCodeType"
)
<input id=
"Submit1"
type=
"submit"
value=
"submit"
/>
<h3>@ViewBag.D</h3>
}
</div>
</body>
</html>
Please help....................
Reply
Answers (
6
)
how to store the session storeg value store in th database
Why is my API throws an error when using authentication mode