如何在asp.net mvc 5中使用dropdownlist更改事件来隐藏和显示div [英] How to hide and show div in asp.net mvc 5 using dropdownlist change event

查看:110
本文介绍了如何在asp.net mvc 5中使用dropdownlist更改事件来隐藏和显示div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的mvc 5项目中使用dropdownlist更改事件隐藏和显示div,我已经研究过了,幸运的是,我在网上发现了这个代码,但它似乎对我没有任何作用,如果有人愿意,我会很感激指出我犯错的地方。
提前致谢

 < script type =text / javascriptsrc =http:// ajax .googleapis.com / AJAX /库/ jquery的/ 1.8.3 / jquery.min.js>< /脚本> 
< script type =text / javascript>
$(function(){
$(document).ready(function(){
$(#CountryID)。change(function(){
if($ (this).val()==Ghana){
$(#showStateLga)。show();
$(#showStateLgaText)。hide();
} else {
$(#showStateLga)。hide();
$(#showStateLgaText)。show();
}
});
});
});
< / script>

Dropdownlist控制:

 < div class =form-group> 
@ Html.LabelFor(model => model.CountryID,htmlAttributes:new {@class =control-label col-md-2})
< div class =col-md- 10\" >
@ Html.DropDownListFor(model => model.CountryID,(IEnumerable< SelectListItem>)ViewBag.cCountryList,--- Select ---,new {@class =form-control})
@ Html.ValidationMessageFor(model => model.CountryID,,new {@class =text-danger})
< / div>
< / div>

Div Control:

 < div id =showStateLgastyle =display:none> 
< div class =form-group>
@ Html.LabelFor(model => model.notState,htmlAttributes:new {@class =control-label col-md-2})
< div class =col-md- 10\" >
@ Html.EditorFor(model => model.notState,new {htmlAttributes = new {@class =form-control}})
@ Html.ValidationMessageFor(model => model.notState ,,新{@class =text-danger})
< / div>
< / div>
< div class =form-group>
@ Html.LabelFor(model => model.notCity,htmlAttributes:new {@class =control-label col-md-2})
< div class =col-md- 10\" >
@ Html.EditorFor(model => model.notCity,new {htmlAttributes = new {@class =form-control}})
@ Html.ValidationMessageFor(model => model.notCity ,,新{@class =text-danger})
< / div>
< / div>
< / div> b


$ b

渲染结果: / p>

 < div class =form-group> 
< label class =control-label col-md-2for =CountryID>国家:< / label>
< div class =col-md-10>
发送“验证码”获取 | 15天全站免登陆