在MVC标题标签的MVC下拉选项 [英] mvc dropdown option with title tag in mvc

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

问题描述

 <选择一个id =优先级>
    <期权价值=日历称号=图标/ icon_calendar.gif>日历和LT; /选项>
    <期权价值=shopping_cart称号=图标/ icon_cart.gif>购物车< /选项>
    <期权价值=CD称号=图标/ icon_cd.gif> CD< /选项>
    <期权价值=选中电子邮件=选择标题=图标/ icon_email.gif>电子邮件和LT; /选项>
    <期权价值=常见问题解答称号=图标/ icon_faq.gif>常见问题< /选项>
    <期权价值=游戏称号=图标/ icon_games.gif>游戏和LT; /选项>
< /选择>

我想这种类型的降下来MVC中的与title属性

  @ Html.DropDownListFor(型号=> model.priority,新的SelectList(ViewBag.Priority,值,文本), - 选择优先级 - 新{@class =需要})


解决方案

内置的DropDownList帮手不允许设置其他HTML个人的选择,如title属性。您必须编写自己的定制帮助,如果你想实现这个目标。这里有一个相同的实现你可以看一看适应您的需求。

<select id="priority">
    <option value="calendar" title="icons/icon_calendar.gif">Calendar</option>
    <option value="shopping_cart" title="icons/icon_cart.gif">Shopping Cart</option>
    <option value="cd" title="icons/icon_cd.gif">CD</option>
    <option value="email"  selected="selected" title="icons/icon_email.gif">Email</option>
    <option value="faq" title="icons/icon_faq.gif">FAQ</option>
    <option value="games" title="icons/icon_games.gif">Games</option>
</select>

I want this type of drop down in mvc with title attribute

 @Html.DropDownListFor(model => model.priority, new SelectList(ViewBag.Priority, "Value", "Text"), "-- Select Priority --", new { @class = "required" })

解决方案

The built-in DropDownList helper doesn't allow you for setting additional HTML attributes on individual options such as title. You will have to write your own custom helper if you want to achieve that. Here's one same implementation you may take a look at adapt to your needs.

这篇关于在MVC标题标签的MVC下拉选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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