DropDownListFor在EditorTemplate没有选择价值 [英] DropDownListFor in EditorTemplate not selecting value

查看:100
本文介绍了DropDownListFor在EditorTemplate没有选择价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义对象的编辑模板。里面的那个编辑模板我用一对夫妇DropDownListFor帮手。在他们每个人我指定一个唯一的模型属性(用pre-选择的值),并包含所有选择选项的选择列表中。

I have an editor template for a custom object. Inside that editor template I use a couple of DropDownListFor helpers. In each of them I specify a unique model property (with the pre-selected value) and the select list containing all the select options.

例如:

<%=Html.DropDownListFor(m => m.DocumentCategoryType, Model.DocumentCategoryTypeList) %>

我知道选项的值是被填充(从查看源)和我的模式是通过在正确的ID值(DocumentCategoryType)。

I know that the option values are being populated (from viewing source) and that my Model is passed in with the correct ID value (DocumentCategoryType).

在视图渲染,但在我的下拉没有选择的项目,因此它默认为第一个(非选择)值。

When the view is rendered, there is no selected item in my dropdown and therefore it defaults to the first (non-selected) value.

有没有人有什么想法?

感谢。

推荐答案

呸。我最终解决它像这样。我希望这被固定RTM。

Yuck. I ended up solving it like this. I hope this gets fixed for RTM.

   <%if(Model!=null){ %>
        <%= Html.DropDownListFor(m => m.DocumentCategoryType, new SelectList(Model.DocumentCategoryTypeList,"Value","Text", Model.DocumentCategoryType))%>
        <%}else{%>
            <%=Html.DropDownListFor(m => m.DocumentCategoryType, Model.DocumentCategoryTypeList) %>
        <%}%>

这篇关于DropDownListFor在EditorTemplate没有选择价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆