IE9 bug with Html.DropDownListFor



你好,我需要一些帮助来解决Internet Explorer 9中的一个错误。我目前正在ASP.NET 4 MVC 3 Razor中开发一些CRUD屏幕。在多屏幕中,我使用@Html.DropDowListFor为外键创建简单的链接。

但是,当我在IE9(而且只有IE9)中使用这些字符时,DropDownList将被渲染为小于其通常大小,文本将显示为比正常值低几个像素,如果显示的单词大于少量字符(不确定是多少,我认为大约是10),它将不会被完全渲染。奇怪的是,当我点击DropDownList时,它会自行修复。

视图代码:

@Html.DropDownListFor(model => model.Asset.FkAssetTypeId, new SelectList(Model.AssetTypes, "AssetTypeId", "Name"))
@Html.ValidationMessageFor(model => model.Asset.FkAssetTypeId)

型号代码:

[Display(ResourceType = typeof(I18N_Asset), Name = "Label_Asset_FkAssetTypeId")]
public int FkAssetTypeId { get; set; }

有人有这个问题的经验,知道解决这个问题的方法吗?谢谢你的帮助。

我发现了问题所在,我在同一页上使用JQuery选项卡。这导致dropdownlistfor-s的前端大小无法缩放到为整个网站设置的css。而是使用JQuery选项卡的frontsize来渲染下拉框,然后将frontsize设置为css。

我已经通过使用Javascript在Document.ready函数中设置字体大小来解决这个问题:

// IE9 causes a bug where the dropdownlists will not be displayed correctly because they won't adapt to their current font-size
// this javascript fixes that by resetting the font-size
if (window.navigator.systemLanguage && (!document.documentMode || document.documentMode === 9)) { //check if IE9 is being used
    var list = document.getElementsByTagName('Select'); // get all dropdownlists
    for (i = 0; i < list.length; i++) {
        list[i].style.fontSize = list[i].style.fontSize; // reset the font-size
    }
}

最新更新