我有一個問題,我無法從視圖索引創建我的模型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'裏面# –