我有一个问题,我无法从视图索引创建我的模型Samochody。我在名为Models的文件夹中创建了这个模型,所有应用都可以工作,但看起来我并不像我想象的那么聪明:D你们能帮助我吗?下面的代码ASP.NET无法从我的视图中引用模型
Samochody.cs型号:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using static WebApplication2.Models.Samochody;
namespace WebApplication2.Models
{
public class Samochody
{
public class Car
{
public int Id { get; set; }
public string Brand { get; set; }
public string Model { get; set; }
public decimal Price { get; set; }
public DateTime Bought { get; set; }
public DateTime Sold { get; set; }
}
}
public class CarDBCtxt : DbContext
{
public DbSet<Car> Cars { get; set; }
}
}
而且Index.cshtml
@model Samochody.Models.Car //error here, can't find Samochody
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
</div>
</body>
</html>
这是我第二次有这种类型的错误,它由2个不同的教程。
'WebApplication2.Models.Samochody.Car'(但你为什么使用嵌套类?) –
嵌套类? –
'class car'在'class Samochody'里面# –