Asp.net mvc 3 Html.DropDownListFor()设置默认选定值MVC3
我想在创建元素时在DropDownList中设置默认的选定值 数据模型:Asp.net mvc 3 Html.DropDownListFor()设置默认选定值MVC3,asp.net-mvc-3,html-helper,html.dropdownlistfor,Asp.net Mvc 3,Html Helper,Html.dropdownlistfor,我想在创建元素时在DropDownList中设置默认的选定值 数据模型: public class CascadingDropDownModel { public int? PreviousFirstListId { get; set; } public int? SelectedFirstListId { get; set; } public int? SelectedSecondListId { get; set; } public string First
public class CascadingDropDownModel
{
public int? PreviousFirstListId { get; set; }
public int? SelectedFirstListId { get; set; }
public int? SelectedSecondListId { get; set; }
public string FirstTextHint { get; set; }
public string SecondTextHint { get; set; }
public IList<DropDownElement> FirstDropDownData { get; set; }
public IList<DropDownElement> SecondDropDownData { get; set; }
public CascadingDropDownModel()
{
FirstDropDownData = new List<DropDownElement>();
SecondDropDownData = new List<DropDownElement>();
}
}
局部视图(工作):
请告诉我问题出在哪里?你有什么错误?我没有错误((如果
SelectedFirstListId
为null,则当页面首次加载时,元素不会选择接收的值,当然不会选择任何值…我在Ajax.BeginForm中使用此DropDownList,SelectedFirstListId则不会选择。)null@PavelIvanov,请分享更多的代码。你应该包括所有的Ajax表单,并解释更多的问题。哟你没有分享到足够的东西让任何人理解或帮助。
@Html.DropDownListFor(
m => m.SelectedFirstListId,
new SelectList(Model.FirstDropDownData, "Id", "Name", Model.SelectedFirstListId),
Model.FirstTextHint)
@Html.DropDownListFor(
m => m.SelectedFirstListId,
new SelectList(Model.FirstDropDownData, "Id", "Name", 5),
Model.FirstTextHint)