I am trying to experiment a little with ASP.NET MVC to get a better feel for it, thus far it has been great, but I am getting a really weird error.
I have a model called Movies.cs with the following code:
public class Movie {
public int Id { get; set; }
public string Name { get; set; }
}
And made a folder called ViewModels with the following file:
public class MoviesMoviesViewModel {
public List<Movie> Movies { get; set; }
}
My controller makes use of these models as:
public ActionResult MoviesC()
{
var movies = new List<Movie>
{
new Movie {Name = "First Movie"},
new Movie {Name = "Sasha Grey vs the Alien Babes of Mars!"},
new Movie {Name = "This is actually fun!"}
};
var movieviewModel = new MoviesMoviesViewModel
{
Movies = movies
};
return View(movieviewModel);
}
Just to finally be used inside my view as:
@model Vidly.ViewModels.MoviesMoviesViewModel
@{
ViewBag.Title = "Movies";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Movies</h2>
@if (Model.Movies.Count == 0)
{
<p>There are no movies to see here.</p>
}
else
{
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Movies</th>
</tr>
</thead>
<tbody>
@foreach (var movie in Model.Movies)
{
<tr>
<td><a href="#">@movie.Name</a></td>
</tr>
}
</tbody>
</table>
}
Just to get an error:
The model item passed into the dictionary is of type 'Vidly.ViewModels.MoviesMoviesViewModel', but this dictionary requires a model item of type 'Vidly.ViewModels.RandomMovieViewModel'.
The weird thing about this error is that RandomMovieVieModel.cs is a file that lives inside the same folder in which MoviesMoviesViewModel.cs lives. But they are not connected in any way whatsoever. I am going through a tutorial and experimenting through it, so I apologize if I am not an alpha master of this. I keep looking around the web to find a solution to this issue but I have been unsuccessful. Any pointers would be greatly appreciated.
BTW. Sorry for the horrible naming conventions, this is code made to be thrown away since I am just trying to get a feel for the framework.