小编Sak*_*bey的帖子

如何将键值对绑定到 MVC4 Razor 中的下拉菜单

我有国家/地区表“tblCountry”,其中有 2 列国家/地区名称、国家/地区 ID,我想显示国家/地区名称,但将国家/地区 ID 存储在其余表中。请告诉我从创建模型到查看的方法,我使用的是数据库优先方法。

public partial class tblRFATCountry
{
    public long CountryID { get; set; }
    public string Country { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试添加字典的模型。

public partial class tblRFATCountry
{
    public long CountryID { get; set; }
    public string Country { get; set; }
    public dictionary<string, long> countryDic = new dictionary<string, long>();
} 
Run Code Online (Sandbox Code Playgroud)

我想做类似的事情,以便我可以显示名称但存储值。请建议

c# razor asp.net-mvc-4

2
推荐指数
1
解决办法
9104
查看次数

标签 统计

asp.net-mvc-4 ×1

c# ×1

razor ×1