EDIT: I haven't found solution to my problem, but i think to this minute that i was not wrong but somehow VS was bugging or me at least.
So i created new project from scratch ( since it is small project just for exercise and did all from the start. Now it is working fine :) so i have no concrete solution for this, i tried everything what you gave me, thank you for your time :)
So I have 2 simple controllers and 2 views. I also have two ViewModels for them separate.
When I try to load Index.cshtml this error occurs:
The model item passed into the dictionary is of type 'Vidly.ViewModels.CustomerViewModel', but this dictionary requires a model item of type 'Vidly.ViewModels.RandomMovieViewModel'.
This is my view model.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Vidly.Models;
namespace Vidly.ViewModels
{
public class CustomerViewModel
{
public List<Customer> Customers { get; set; }
}
}
This is my view:
@model Vidly.ViewModels.CustomerViewModel
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
And a controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidly.Models;
using Vidly.ViewModels;
namespace Vidly.Controllers
{
public class CustomersController : Controller
{
// GET: Customers
public ActionResult Index()
{
var customers = new List<Customer>
{
new Customer {Id = 1, Name = "Willy Wonka"},
new Customer {Id= 2 , Name = "Walter White"}
};
var viewModel = new CustomerViewModel
{
Customers = customers
};
return View(viewModel);
}
}
}
However, I can't find why does it load this model:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Vidly.Models;
namespace Vidly.ViewModels
{
public class RandomMovieViewModel
{
public Movie Movie { get; set; }
}
}