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
Guest User
Tech Writer
2.1k
473.4k
System.InvalidOperationException: 'There is no ViewData item of type '
Sep 7 2020 6:33 AM
Hi Team
I am trying to fix this errror and was not successfull, can anyone mate help me on this error.
public
ActionResult CourseList()
{
var list =
new
List<
string
>() {
"Private(Copyrighted)"
,
"Public Domain"
,
"Creative Commons Licences"
,
"CC Attribution"
,
"CC Attribution Share ALike"
,
"CC Attribution Non-Commercial"
,
"CC Attribution Non-Commercial Share Alike"
,
"CC Attribution Non Directive"
,
"CC Attribution Non-Commercial No Directives"
};
List<SelectListItem> select_list =
new
List<SelectListItem>();
var query = from li
in
list
select
new
SelectListItem()
{
Value = li.ToString(),
Text = li.ToString(),
};
select_list = query.ToList();
ViewBag.list = select_list;
return
View();
}
@
using
(Html.BeginForm(
"CourseList"
,
"Home"
, FormMethod.Post))
{
<div
class
=
"form-group row"
>
<label
for
=
"Content-Licence"
class
=
"col-sm-3 col-form-label"
>Content Licence</label>
<div
class
=
"col-sm-5"
>
@Html.DropDownListFor(m => Model.Dashboard.CourseLicence, ViewBag.list
as
List<SelectListItem>)
// This throws an error here: no ViewData item of type.
</div>
</div>
}
public
class
RegCoursesViewModel
{
public
eNtsaCourses Courses {
get
;
set
; }
public
eNtsaDashboardViewModel Dashboard {
get
;
set
; }
public
List<eNtsaDashboardViewModel> lsteNtsaDashboard {
get
;
set
; }
public
RegCoursesViewModel MainModel {
get
;
set
; }
}
Reply
Answers (
2
)
Dropdownlistfor On your View return null, how to fix it?
Acquiring all roles an authenticated user has in