我需要通过使用MVC传递url中的值来自动从下拉列表中选择一个值 [英] I need to select one value from dropdown list automatically by passing the value in url using MVC

查看:66
本文介绍了我需要通过使用MVC传递url中的值来自动从下拉列表中选择一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下面列出的下拉列表。当我点击网址时,我想自动在下拉列表中选择所需的值。



选择POR来获取清单

901:R服务器季刊(季度更新;产品/ PFAM重命名)

913:用于MAC的Visual Studio(媒体发布)







让我们说如果我想自动选择901值,我希望这个值应该在url中传递,点击它时应该使用mvc选择value.am.



我的网址是@urlaction(PORChecklist,Tables)。如何通过使用此URL自动从下拉列表中选择值。



我尝试过:



我在视图中使用了jquery自动选择值,但我现在已经对这个值进行了编码。





函数selectFromDropdown(选择器,文本){

$(选择器).find('option')。each(function(){

if($(this) .text()== text){

$(选择器).val($(this).val());



返回false;

}

})

}

setTimeout(function(){

selectFromDropdown('#PORList','913:Visual Studio for MAC(媒体发布)')

},

它对我来说运行正常。但是要求我需要想传递所需的值,只需通过网址选择。



这里是代码片段,其中包含控制器页面中的选项列表。

public ActionResult PORChecklist()

{



List< string> dropdown_content = new List< string>();

dropdown_content = DOMEHelper.FufillmentChecklistPORs();

SelectList list = new SelectList(dropdown_content);



ViewBag.ListOfPORs = list;

return View();



}

i have a dropdown list with below values. when i click on url, i wanted to select the required value in the dropdown automatically.

select POR to fetch checklist
901:R Server Quarterly (Quarterly Update; Product/PFAM rename)
913:Visual Studio for MAC (media launch)



let's say if i want to select 901 value automatically, i wanted this value should be passed in the url and on clicking it should select the value.am using mvc.

my url is @urlaction("PORChecklist","Tables"). how do i select the value automatically from dropdown by using this url.

What I have tried:

I have used jquery in view for selecting the value automatically but i harcoded the value as of now.


function selectFromDropdown(selector, text) {
$(selector).find('option').each(function () {
if ($(this).text() == text) {
$(selector).val($(this).val());

return false;
}
})
}
setTimeout(function () {
selectFromDropdown('#PORList', '913:Visual Studio for MAC (media launch)')
},
it is working fine for me. but as requested i would need like wanted to pass the required value that need to be selected through url only.

here is the code snippet which holds the list of options in controller page.
public ActionResult PORChecklist()
{

List<string> dropdown_content = new List<string>();
dropdown_content = DOMEHelper.FufillmentChecklistPORs();
SelectList list = new SelectList(dropdown_content);

ViewBag.ListOfPORs = list;
return View();

}

推荐答案

(选择器).find('option')。each(function(){

if(
(selector).find('option').each(function () {
if (


(this).text()== text){
(this).text() == text) {


(selector).val(
(selector).val(


这篇关于我需要通过使用MVC传递url中的值来自动从下拉列表中选择一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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