javascript - 邮政编码和城市列表,excel 方舟还是数据库?

标签 javascript asp.net-mvc razor

我有这个丹麦邮政编码列表(可在线获取),现在我把它作为一个 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/

相关文章:

javascript - 使用 Requirejs 时,是否可以让优化器自动找到所有依赖项?

javascript - jQuery - JavaScript 正则表达式仅允许数字和减号作为第一个字符

javascript - AngularJs 在 ng-repeat 中设置单个点击元素的样式

asp.net - 使用 jQuery 在 HTML 选择列表中添加/删除项目

asp.net-mvc-3 - System.Web.Mvc.HtmlHelper<dynamic> 不包含 'Syncfusion' 错误的定义

asp.net-mvc - 在 ASP.NET MVC Razor View 中将换行符替换为 <br/>

javascript - Visual Studio Code "Cick-Through/Go-To"不适用于 jsconfig.json(和 Next.js)中的路径别名

c# - 提交后 IEnumerable 属性为空

asp.net-mvc - 默认情况下 ASP.NET MVC 4 是否需要额外的 XSS 处理

javascript - 在asp.net mvc中使用jquery ajax提交帖子后更新部分 View