我正在開發使用C#和SQL Server 2005的ASP .Net MVC 3應用程序。
我也使用實體框架和代碼優先方法。
我已經創建了一個'DropDownList'來從我的基表中加載數據。
但因此,此DropDownList告訴我:'NameofApplication.Models.NameofTable'
我不知道爲什麼?
這是DROPDOWNLIST的視圖中的聲明:從DropDownList的基礎加載數據的錯誤ASP MVC 3和EF
<%:Html.Label("Gamme :")%>
<%: Html.DropDownList("ID_Gamme", String.Empty) %>
這是Profile_Ga的控制器:
namespace MvcApplication2.Controllers
{
public class ProfileGaController : Controller
{
private GammeContext db = new GammeContext();
//
// GET: /ProfileGa/
public ViewResult Index(Profile_Ga profile_ga)
{
ViewBag.ID_Gamme = new SelectList(db.Profil_Gas, "ID_Gamme", profile_ga.ID_Gamme);
return View(db.Profil_Gas.ToList());
}
和Finaly這是模型:
namespace MvcApplication2.Models
{
public class Profile_Ga
{
[Required]
[Key]
[Display(Name = "ID Gamme:")]
public string ID_Gamme { get; set; }
[Required]
[Display(Name = "Gamme Entrante:")]
public string In_Ga { get; set; }
[Required]
[Display(Name = "Gamme Sortante:")]
public string Out_Ga { get; set; }
[Required]
[Display(Name = "Gamme Suivante:")]
public string Next_Gamme { get; set; }
[Required]
[Display(Name = "Etat:")]
public string Etat { get; set; }
}
}
PS :
表中的表名是Profile_Ga
隨着你最近的評論下面,那麼我的第一個答案是正確的。請嘗試並做到這一點。所以你應該在你的控制器方法中使用'返回View(db.Profil_Gas.ToList());'和<%:Html.DropDownList(「ID_Gamme」,new SelectList(Model,「ID_Gamme」,「ID_Gamme」))% >在你看來。請記住,您的模型是'Profile_Ga'的集合。 – 2013-05-07 09:56:55
非常感謝!這是完美的作品! – anouar 2013-05-07 10:07:04
很酷,最後,歡迎您:) – 2013-05-07 10:13:16