在Asp.Net Mvc 4.0中使用Optgroup下拉列表 [英] Dropdown With Optgroup In Asp.Net Mvc 4.0

查看:62
本文介绍了在Asp.Net Mvc 4.0中使用Optgroup下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在asp.net MVC4中使用带有OptionGroup的下拉列表。

i已经用Google搜索了这一点,我得知在此功能的下拉列表中没有支持。 />


我会很感激,如果有人能帮助我,我怎么能在MVC4中实现这个目标。



谢谢你提前。

解决方案

我正在添加并接受此解决方案,以帮助其他寻求相同的人...





在搜索这个时我已经找到了一些方法..



1.

通过创建自己的HTML Helper,您可以实现这一功能。

在搜索之后,我已经创建了一个由其他开发人员通过此链接开发的HTML Helper ... https://github.com/bhaumikpatel/DDL.optgroup.MVC.Demo [ ^ ]



2.

第二种方法是从Ajax请求获取数据并通过JQTemplate绑定它。

我找到了有用的链接这...

http://stackoverflow.com/ questions / 7634137 / two-dimensional-list-inside-jquery-template [ ^ ]



3.

我通过创建动态完成了这项工作获取数据后的HTML


.POST ...



控制器方法代码...

  //  我采取了为我构建数据的元组...  
// List< Tuple< OptionGroupName,OptionValueArray,OptionTextArray>>
List< T uple< string, int [], string []>> datalist = new List< Tuple< string, int [],字符串 []>>();


// 然后向此元组添加数据...
datalist.Add( new 元组< string,> Job1 new int [] { 1 2 3 }, new string [] { Batch1 Batch2 Batch3}));

return Json(datalist);





我的Ajax调用就像......

 


.ajax({
type:'POST' ,
url:/+ controller +/+ action +/+ id,
success:function(data){

// < OptionGroup 标签:JobName > < / OptionGroup >
// < 选项 值:BatchID > 内容:BatchName> < / Option >


var _Content ='< 选择 名称 = BatchID id = BatchDropDown > < 选项 = > 选择批次< < span class =code-leadattribute> / option > ';

I need to use dropdown with OptionGroup in asp.net MVC4.
i have Googled this and i got that there is no support in dropdownlist for this functionality.

I will be thankful if anyone can help me that how can i achieve this in MVC4.

Thanks in Advance.

解决方案

I am Adding And Accepting this as Solution to help others who are seeking for the same...


While Searching on this i have founded few ways..

1.
By Creating your own HTML Helper you can achieve the functionality.
And After Searching for i have founded one HTML Helper developed by another developer from this link...https://github.com/bhaumikpatel/DDL.optgroup.MVC.Demo[^]

2.
The Second way was to get data from Ajax request and binding it by JQTemplate.
I have found useful link to do this...
http://stackoverflow.com/questions/7634137/two-dimensional-list-inside-jquery-template[^]

3.
I have done this by Creating dynamic HTML after getting data by


.POST...

Controller Method code...

// I have taken Tuple that will construct data for me...
// List<Tuple<OptionGroupName, OptionValueArray, OptionTextArray>>
List<Tuple<string, int[], string[]>> datalist = new List<Tuple<string, int[], string[]>>();


//Then Added Data To This Tuple like...
datalist.Add(new Tuple<string,>("Job1", new int[] {1,2,3}, new string[] {"Batch1","Batch2","Batch3"}));

return Json(datalist);



And My Ajax call is like...


.ajax({ type: 'POST', url: "/" + controller + "/" + action + "/" + id, success: function (data) { // <OptionGroup Label:JobName></OptionGroup> // <Option Value:BatchID>Content:BatchName></Option> var _Content = '<select name="BatchID" id="BatchDropDown" ><option value="">Select Batch</option>';


这篇关于在Asp.Net Mvc 4.0中使用Optgroup下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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