如何使用MVC 4在@ Html.ListBoxFor中选择特定项? [英] How to select particular item in @Html.ListBoxFor using MVC 4?

查看:57
本文介绍了如何使用MVC 4在@ Html.ListBoxFor中选择特定项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何选择@ Html.ListBoxFor控件的真正特定项目。

我知道在@ Html.ListBoxFor控件中选择true所有项目 -

Hi,
How to select true particular item of @Html.ListBoxFor control.
I know for selecting true all items in the @Html.ListBoxFor control-

$("#List").find("option").attr("selected", true);





请建议如何使用JQUERY选择@ Html.ListBox中的特定项目。



请建议。

谢谢。



Please suggest how to select particular item in @Html.ListBoxFor control using JQUERY.

Please suggest.
Thanks.

推荐答案

#List )。find( option)。attr( 选中 true );
("#List").find("option").attr("selected", true);





请建议如何使用JQUERY选择@ Html.ListBox中的特定项目。



请建议。

谢谢。



Please suggest how to select particular item in @Html.ListBoxFor control using JQUERY.

Please suggest.
Thanks.


方法1:



Method 1:

@Html.ListBox(m => m.Names, (IEnumerable<SelectListItem>)(new[] { new SelectListItem() { Value = "1",Text="Abc",Selected=true }}))



方法2:




Method 2:

@Html.ListBoxFor(m => m.Names, new SelectList(new listName_With_Id()(), "Id", "Name", "9"), new { Class = "ControlName"})





这里将选择带有9的Id。



Here Id with 9 will be selected.


这篇关于如何使用MVC 4在@ Html.ListBoxFor中选择特定项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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