Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DropDownList呈现不同的Html。隐藏选择和可见列表_C#_Asp.net_Asp.net Mvc - Fatal编程技术网

C# DropDownList呈现不同的Html。隐藏选择和可见列表

C# DropDownList呈现不同的Html。隐藏选择和可见列表,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,我是ASP.NET MVC新手,但我曾在ASP.NET WebForms上工作过。 我正在尝试创建一个下拉列表。我读了这篇文章。 这是我的密码 控制器: ViewData["Categories"] = new List<SelectListItem>() { new SelectListItem(){Text = "cate 1", Value = "1"},

我是ASP.NET MVC新手,但我曾在ASP.NET WebForms上工作过。 我正在尝试创建一个下拉列表。我读了这篇文章。 这是我的密码 控制器:

 ViewData["Categories"] = new List<SelectListItem>()
        {
            new SelectListItem(){Text = "cate 1", Value = "1"},
            new SelectListItem(){Text = "cate 2", Value = "2"},
            new SelectListItem(){Text = "cate 3", Value = "3"},
            new SelectListItem(){Text = "cate 4", Value = "4"},
            new SelectListItem(){Text = "cate 5", Value = "5"}
        };
        return View();
ViewData[“Categories”]=新列表()
{
新建SelectListItem(){Text=“cate 1”,Value=“1”},
新建SelectListItem(){Text=“cate 2”,Value=“2”},
新建SelectListItem(){Text=“cate 3”,Value=“3”},
新建SelectListItem(){Text=“cate 4”,Value=“4”},
新建SelectListItem(){Text=“cate 5”,Value=“5”}
};
返回视图();
视图:


@Html.DropDownList(“Category”,(IEnumerable)ViewData[“categories”])
@Html.DropDownListFor(model=>model.Category,(IEnumerable)ViewData[“Categories]”);
型号:

    public class Home {
    public int Category { get; set; }

    public List<string> CategoryList { get{return new List<string>(){"cate1","cate2","cate3","cate4",};} }
}
公共类主页{
公共int类{get;set;}
公共列表CategoryList{get{return new List(){“cate1”、“cate2”、“cate3”、“cate4”、};}
}
这是以Home命名的,因为我将其用作viewModel。实际的模型类是不同的,尚未交互

以下是我得到的输出:


abybody能否帮助您在没有显示的情况下获取onlu select part:none?

正如@David在评论中提到的,是名为jquery.nice select.min.js的js库生成了这样的结果。
抱歉

看起来您可能有一些JavaScript插件正在用样式化的
元素替换
元素。您是否尝试过添加自己的CSS,如@Html.DropDownListFor(model=>model.Category,(IEnumerable)ViewData[“Categories”],new{@class=“dropdown”});或者将@class=下拉列表替换为style=“display:none”@David我将在js libs中查看一下,因为我正在为这个UI使用模板,模板可能包含一些代码,就像我在另一个模板中体验到的一样。。。我是后端开发人员,这就是为什么我在前端开发方面如此薄弱的原因谢谢@David,是jquery.nice-select.min.js破坏了select元素。
    public class Home {
    public int Category { get; set; }

    public List<string> CategoryList { get{return new List<string>(){"cate1","cate2","cate3","cate4",};} }
}