分配属性为@ Html.DropdownList [英] Assign Attribute to @Html.DropdownList

查看:111
本文介绍了分配属性为@ Html.DropdownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要分配一些ID属性名称是使用来自ViewBag数据作为我的下拉列表中,

I want to assign some ID attribute name to my Dropdown list which is using data from the ViewBag as,

ViewBag.Group = new SelectList(group, "GroupId", "Name");

和在视图侧我用剃刀语法显示下拉为,

and in the View side I have used Razor syntax for showing the Dropdown as,

@Html.DropDownList("Group", "New", new { id="testID" } )

但是我收到这条线上的错误。可我只是转让本剃刀语法的ID?
我知道ID与名称播放列表生成,但我使用相同的ViewBag有2个不同的下拉菜单。正因为如此,我必须为它们分配不同的ID属性值。如何能做到?

But I am getting the error on this line. Can I just assign ID of This Razor syntax? I know that the ID is generated with the Name "Playlist" But I am having 2 different dropdowns using same ViewBag. Because of that I have to assign different "ID" attribute value for them. How can it be done?

推荐答案

您应该使用这样的事情

@Html.DropDownList("Group",null,new{@id="testID"});

因为DropDownList中的数据来自ViewBag命名

这篇关于分配属性为@ Html.DropdownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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