我有一个控件,需要有多个选择选项来创建令牌。每当创建或删除令牌时,都会生成DB调用。现在问题是当我从服务器加载一个新页面时,控件中没有令牌。以下是我的Razor代码:
@Html.DropDownList("ProjectIds", new MultiSelectList(projDDL.Items, "key", "value",Model.SelectedProject), new {@class = "form-control selectorBind", multiple = "multiple",@id= "myid" data_rowid = "ID", data_type="Project",data_myattr= "attr" })
projDDL 是一个包含下拉列表项
的字典SelectedProject 也是包含所选项目键,值
的字典我试图关注此链接MVC DropDown list with MultipleSelect,但没有运气。
从服务器端加载令牌是我的问题。虽然我知道我可以从Jquery轻松完成,但我想使用Razor。
的解决方案 的
查看@Html.DropDownListFor
vs @Html.ListBoxFor
@Html.ListBoxFor(y => y.SelectedProjects, new MultiSelectList(projDDL.Items, "key", "value", Model.SelectedProjects), new { @class = "form-control selectorBind", multiple = "multiple", @id = @Model.SkillType+"Project_" + Model.ID, data_rowid = @Model.ID, data_type = "Project", data_myattr = "FK_ProjectID" })
答案 0 :(得分:1)
查看@Html.DropDownListFor
和@Html.ListBoxFor
之间的差异以及何时使用
@Html.ListBoxFor(y => y.SelectedProjects, new MultiSelectList(projDDL.Items, "key", "value", Model.SelectedProjects), new { @class = "form-control selectorBind", multiple = "multiple", @id = @Model.SkillType+"Project_" + Model.ID, data_rowid = @Model.ID, data_type = "Project", data_myattr = "FK_ProjectID" })