我正在使用 C# 和 SQL Server 2005 开发一个 ASP.Net MVC 3 应用程序。我正在使用具有代码优先方法的实体框架。
我有一个带有 Views(Index,Create,...) 的模型 Profile_Ga。
我在该模型的索引中创建了一个 DropDownList 来加载 ID (ID_Gamme)。
我现在想在 Profil_Ga 的索引中加载另一个表(另一个模型是 Poste)的 ID。
但总是出现这个错误:
DataBinding:“MvcApplication2.Models.Profile_Ga”不包含名为“ID_Poste”的属性。
这是 Profile_Ga 的控制器:
namespace MvcApplication2.Controllers
{
public class ProfileGaController : Controller
{
private GammeContext db = new GammeContext();
//
// GET: /ProfileGa/
public ViewResult Index(Profile_Ga profile_ga, Poste poste)
{
ViewBag.ID_Gamme = new SelectList(db.Profil_Gas, "ID_Gamme", profile_ga.ID_Gamme);
ViewBag.ID_Poste = new SelectList(db.Postes, "ID_Poste", poste.ID_Poste);
return View(db.Profil_Gas.ToList());
}
这就是我在索引中添加的内容:
<%:Html.Label("Gamme :")%>
<%: Html.DropDownList("ID_Gamme", new SelectList(Model, "ID_Gamme", "ID_Gamme ")) %>
<%:Html.Label("Poste :")%>
<%: Html.DropDownList("ID_Poste", new SelectList(Model, "ID_Poste", "ID_Poste ")) %>