无法将级联下拉列表中的值插入数据库 [英] Can't insert value from cascading dropdownlist to database
问题描述
嘿,我是新来的这个
i已经通过脚本jason创建了级联下拉列表
但是当我尝试插入这些数据时,我只能插入国家而不是国家&城市没有插入为什么国家& City不仅仅插入数据库国家和我的代码
< ;! - - 国家/地区 - > 跨度>>
< div < span class =code-attribute> class = form-group >
@ Html.LabelFor(model => model.Country,htmlAttributes:new {@class =control-label col-md-2})
< div < span class =code-attribute> class = col-md-10 >
@ Html.DropDownList(countryId,(SelectList)ViewBag.SelectCountry,select please,new {@class =form-control })
@ Html.ValidationMessageFor(model => model.Country,,new {@class =text-danger})
&l t; / div >
< / div >
<! - 状态 - > 跨度> 跨度>>
< div < span class =code-attribute> class = form-group >
@ Html.LabelFor(model => model.States,htmlAttributes:new {@class =control-label col-md-2})
< div < span class =code-attribute> class = col-md-10 >
< select id = statelistdrop class = form-control name = > < / select >
@ Html.ValidationMessageFor(model => model.States,,new {@class =text-danger})
< / div >
< / div >
<! - 城市 - > >
< div < span class =code-attribute> class = form-group >
@ Html.LabelFor(model => model.City,htmlAttributes:new {@class =control-label col-md-2})
< div < span class =code-attribute> class = col-md-10 >
< select id = citieslistdrop class = form-control > < / select < span class =code-keyword>>
@ Html.ValidationMessageFor(model => model.City,,new {@class =text-danger})
< / div >
< / div >
和这里我的级联下拉列表的脚本
<前lang =Javascript>< script>
$( function (){
$( #countryId)。change( function (){
$ .get( / Country / GetStatesById,{ID:$( #countryId)。val()}, function (data){
$( #statelistdrop)。empty();
$ .each(data, function (index,row){
$( #statelistdrop).append( < option value =' + row.state_id + '> + row.name + < / option>)
});
})
});
});
< / script>
< script>
$( function (){
$( #statelistdrop)。change( function (){
$ .get( / Country / GetCitiesById,{ID:$( #statelistdrop)。val()}, function (data){
$( #citieslistdrop)。empty();
$ .each(data, function (index,row){
$( #citieslistdrop).append( < option value =' + row.state_id + '> + row.name + < / option>)
});
})
});
});
< / script>
我的尝试:
i尝试更改剃刀代码但不起作用
( function (){
( #countryId )。change( function (){
.get( / Country / GetStatesById,{ID:
hey there i'm new on this
i already create cascading dropdownlist by script jason
but when i try to insert this data i can only insert Country but States & City not insert why States & City not insert to database only just Country and here my code
<!--Country-->>
<div class="form-group">
@Html.LabelFor(model => model.Country, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("countryId", (SelectList)ViewBag.SelectCountry, "select please", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Country, "", new { @class = "text-danger" })
</div>
</div>
<!--States-->>
<div class="form-group">
@Html.LabelFor(model => model.States, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="statelistdrop" class="form-control" name=""></select>
@Html.ValidationMessageFor(model => model.States, "", new { @class = "text-danger" })
</div>
</div>
<!--City-->>
<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select id="citieslistdrop" class="form-control"></select>
@Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
</div>
</div>
and here my script for cascading dropdownlist
<script>
$(function () {
$("#countryId").change(function () {
$.get("/Country/GetStatesById", { ID: $("#countryId").val()}, function (data) {
$("#statelistdrop").empty();
$.each(data, function (index,row) {
$("#statelistdrop").append(" <option value='" + row.state_id + "'>" + row.name+ "</option>")
});
})
});
});
</script>
<script>
$(function () {
$("#statelistdrop").change(function () {
$.get("/Country/GetCitiesById", { ID: $("#statelistdrop").val() }, function (data) {
$("#citieslistdrop").empty();
$.each(data, function (index,row) {
$("#citieslistdrop").append(" <option value='" + row.state_id + "'>" + row.name + "</option>")
});
})
});
});
</script>
What I have tried:
i try to change razor code but didn't work
(function () {
("#countryId").change(function () {
.get("/Country/GetStatesById", { ID:
这篇关于无法将级联下拉列表中的值插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!