我有这个丹麦邮政编码列表(可在线获取),现在我把它作为一个 Excel 方舟。但一直想知道是否最好将其放入我的数据库中。
我对两个编辑器都有这个 View
<div class="form-group">
@Html.LabelFor(model => model.Postnr, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Postnr, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Postnr, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.By, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.By, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.By, "", new { @class = "text-danger" })
</div>
</div>
当 Postnr 模糊时,我想使用 javascript 更新 by(city)。有什么好主意如何做到这一点?
999 København C
1000 København K
1050 København K
1051 København K
1052 København K
1053 København K
1054 København K
1055 København K
1056 København K
1057 København K
1058 København K
1059 København K
1060 København K
1061 København K
1062 København K
1063 København K
1064 København K
1065 København K
Excel 中文本的示例
最佳答案
根据要求..这是一个 Ajax 帖子示例。
$(document).on("click","#btnYOURBUTTON", function () {
var newPostnrValue = $('#postnrTextBoxName').val();
$.ajax({
type: "POST",
url: "@Url.Action("YourAction", "YourController")",
data: newPostnrValue
});
});
多个参数
$(document).on("click","#btnYOURBUTTON", function () {
var param1Value= $('#param1Value').val();
var param2Value= $('#param2Value').val();
$.ajax({
type: "POST",
url: "@Url.Action("YourAction", "YourController")",
data: {paramName1: param1Value, paramName2: param2Value}
});
});
pramName1 等...必须与 Controller 操作方法参数名称的拼写完全匹配。
或者发布整个表格。即您的 View html 包含在表单标记中。
$(document).on("click","#btnYOURBUTTON", function () {
var myData = $('#YourFormID').serialize();
$.ajax({
type: "POST",
url: "@Url.Action("YourAction", "YourController")",
data: myData,
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
});
});
希望有帮助。
关于javascript - 邮政编码和城市列表,excel 方舟还是数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776762/