我创造MVC3搜索应用程序,我有2个表:ID(PK),S_ID(FK),District_name如何在MVC3中动态地填充下拉列表?
我: 1.State:ID(PK)和STATE_NAME 2.District首先使用代码和EF和具有数据库创建了它所谓的搜索
我希望我的索引显示在下拉所有状态下拉列表
以下是我State.cs代码
public partial class State
{
public State()
{
this.Districts = new HashSet<District>();
this.Search_master = new HashSet<Search_master>();
}
public int Id { get; set; }
public string State_name { get; set; }
public virtual ICollection<District> Districts { get; set; }}
这是我区等级:
public partial class District
{
public District()
{
this.Search_master = new HashSet<Search_master>();
}
public int Id { get; set; }
public string District_name { get; set; }
public int StateId { get; set; }
public virtual State State { get; set; } }
我如何可以调用存储在我的表中的数据在我的索引页 感谢你提前!
:日Thnx的答复... BT我仍然没得到那个... u能帮助我...我更新了我的答案! – EqEdi 2012-03-06 11:51:57
您应该使用两个SelectList创建一个模型。一个FO状态,一个用于区和int STATEID和int DistrictId并结合他们soemthing这样的:model.States =新的SelectList(repository.GetStates(), “ID”, “姓名”,model.StateId); – Iridio 2012-03-06 13:31:16
:Thnx ..... bt我得到一个错误在repository.GetStates().....我需要创建它吗?如果是这样的话,我应该在哪里放入...在Viewmodel中? – EqEdi 2012-03-07 05:19:40