【发布时间】:2022-01-26 07:27:49
【问题描述】:
这里的方法不起作用。
这是我的cshtml:
<div class="form-group col-md-4">
<label for="inputState">City</label>
<select id="City" class="form-control basic" asp-for="City"
asp-items="@(new SelectList(ViewBag.Cities," Id","ZoneName"))"
readonly="@(Model.IsView ? true : false)">
<option value="0" selected>Select</option>
</select>
</div>
jQuery
$("#CustomerName").change(function () {
var CustomerName = $("#CustomerName").val();
$.ajax({
url: "../Ticket/FetchCustomerAddress",
data: { userId: CustomerName },
type: "Get",
success: function (data) {
alert(data.city);
//debugger;
$('#City').val(data.city);
},
error: function (err) {
//console.error(err)
//alert("Internal server error.");
}
})
});
我正在用城市填充列表。我想自动选择从data.city获取的列表中的城市
【问题讨论】:
-
嗨@Sharad Kulshrestha。你能分享你的模型设计吗?此外,我看到你使用
alert(data.city);,它会提醒正确的值吗?另外,如果可能,请分享您的FetchCustomerAddress返回数据。
标签: javascript html jquery asp.net-core