我的控制器:
public class ManufacturersController : Controller
{
public Manufacturer_vm man1 { get; set; }
public ManufacturersController()
{
this.man1 = new Manufacturer_vm();
}
//
// GET: /Manufacturerers/
public ActionResult Index()
{
if (Session["manufacturer"] != null)
{
man1 = (Manufacturer_vm)Session["manufacturer"];
}
return View(man1);
}
}
在我看来:
@model Example.Controllers.ManufacturersController.Manufacturer_vm
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
但是它说“类型名称'Manufacturer_vm'在类型'Example.Controllers.ManufacturersController
中不存在我有另一类Manufacturer_vm,我得到变量man1但是我无法使用索引视图而无法添加@model
这是我的Manufacturer_vm类
public class Manufacturer_vm
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public int YearStarted { get; set; }
public ICollection<Vehicle_vm> Vechicles { get; set; }
public Manufacturer_vm()
{
this.Id = 0;
this.Name = "Car";
this.Country = "Canada";
this.YearStarted = 0;
this.Vechicles = new List<Vehicle_vm>();
}
public class Manufacturer
{
public ICollection<Manufacturer_vm> Manufacturer { get; set; }
public Manufacturer()
{
this.Manufacturer = new List<Manufacturer_vm>();
}
}
}
答案 0 :(得分:1)
您似乎没有在Manufacturer_vm
中定义ManufacturersController.
您的控制器中只有Manufacturer_vm
类型的属性。在设置模型时,您应该指定您的类定义在哪里。您可以将其定义到模型中,查看namespace
的{{1}}是否在Manufacturer_vm class,
文件夹中你应该用这个:
Controller