得到razor Dropdownlist到javascript [英] getting razor Dropdownlist to javascript

查看:67
本文介绍了得到razor Dropdownlist到javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Razor Dropdownlist:

I am using Razor Dropdownlist as:

@Html.DropDownList("TnDscode",null,new{@id="cmbTnDscode" ,@size="1.2"})





在下拉列表的控制器代码中:



In controller code for Dropdownlist:

ViewBag.TnDscode = new SelectList(db.Districts, "DsCode", "DsName");





在JavaScript中:



In JavaScript:

document.getElementById("cmbTnDscode").value="Mumbai"; 





但它无效...

将Dropdownlist的选定值设置为Mumbai可以有人帮忙??



But It is not working...
to set selected value of Dropdownlist to "Mumbai" can anyone help??

推荐答案

嗨Priyanka,



请试试这个代码



Hi Priyanka,

Please try this code

document.getElementById('cmbTnDscode').value = 'DsCode value'





你必须写入值等于你在控制器中使用的DsCode。



you have to write value equals "DsCode" which you have use in controller.


这篇关于得到razor Dropdownlist到javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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