假设我有以下对象:
public class CountryAndState
{
public string Country { get; set; }
public List<string> States { get; set; }
}
这个对象在我的视图中被填充,如下所示:
<select id="CountryDropdown" name="CountrySelector">
@foreach (CountryAndState cas in Model.CountryAndState())
{
<option value="@cas.country">@cas.country</option>
}
</select>
问题是,我想用状态填充第二个dropdownlist
,这取决于在上面的dropdownlist
中选择了哪个国家。
然而,我似乎无法访问这个dropdownlist
的ID,以便在我的剃刀代码中获得下一个状态下拉列表的依赖项。
- 因此,我如何添加此依赖项,并根据第一个国家中所选的国家动态填充我的州下拉列表
use the jquery min
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
$(document).ready(function(){
$('#CountryDropdown').change(function () {
var txt = $("#CountryDropdown option:selected").text();
var v = $("#CountryDropdown").val();
here add the dropdown of state
})
});