好的,我有一个带有以下Razor语法的视图:
@model DoggrOPI.Models.WellSearch
<div class="container-fluid">
<h2>Well Search</h2>
@for (int i = 0; i < Model.Counties.Count; i++)
{
@Html.DisplayFor(m => m.Counties[i].CountyName)
}
</div>它显示:
Value 1Value 2Value 3这正是我想要的,但我不能将其绑定到@Html.DropDownListFor。这样做的正确语法是什么?
我的模型是这样的:
public partial class CountyInfo
{
public string CountyName { get; set; }
}发布于 2014-11-07 08:46:30
型号:
public class WellSearch
{
public int CountyId { get; set; }
public IEnumerable<CountyInfo> Counties { get; set; }
}
public partial class CountyInfo
{
public int CountyId {get; set;}
public string CountyName { get; set; }
}查看:
@Html.DropDownListFor(m => m.CountyId , new SelectList(Model.Counties), "CountyId", "CountyName "))基本上,在您的主视图模型中添加一个CountyId,当您将表单发送到服务器时,它将匹配您选择的下拉选项。
https://stackoverflow.com/questions/26791250
复制相似问题