MVC razor页面jQuery触发但在页面刷新之前不填充字段(MVC razor page jQuery fires but doesn't fill field until page

编程入门 行业动态 更新时间:2024-10-28 02:35:44
MVC razor页面jQuery触发但在页面刷新之前不填充字段(MVC razor page jQuery fires but doesn't fill field until page refreshes)

Visual Studio 2012 MVC 5.1.1 ASP.Net Razor 3.1.1 bootstrap 3.1.1 jQuery 2.1.0 json.Net 6.0.1 Web优化1.1.3 Webgrease 1.6.0 等 - 大多数新的扩展等

我有一个MVC Web应用程序与Telerik MVC KendoUI ComboBoxFor ComboBoxes在剃刀局部视图:

@model HTPortal.ViewModels.ClientInquiryViewModel @using System.Web.UI.WebControls @using Kendo.Mvc.UI <div class="form-group"> @Html.LabelFor(model => model.AddressState, new { @class = "control-label col-sm-2 col-md-2 col-lg-2" }) <div class="col-sm-5 col-md-5 col-lg-5"> @(Html.Kendo().ComboBoxFor(model => model.AddressState) .Placeholder("Select Province...") .DataTextField("ProvinceName") .DataValueField("ProvinceName") .Suggest(true) .BindTo(Model.Provinces) ) </div> </div>

数据被加载到组合框中 - 一切正常。

在父razor页面中,在@using(Html.BeginForm())块之后,我有:

@section Scripts { <script type="text/javascript"> $(document).ready(function () { $.getJSON("http://smart-ip.net/geoip-json?callback=?", function (data) { alert(data.region); //$("#AddressCity").val(data.city); $("#AddressState").val(data.region); //$("#AddressCountry").val(data.countryName); }); }); </script> }

在第一页加载时,警报会触发,我会在警报中显示我的省/州。 但是,在刷新页面后,我的名为AddressState的Combobox才会被填充。

我已经阅读了类似问题的其他各种帖子,但没有窗口加载或初始化或任何工作。

事实上,在IE和Chrome中 - 我得到的只是警报对话框 - 字段永远不会被填充。

帮帮我....

如何在第一次调用页面时让这个jQuery填充该字段?

Visual Studio 2012 MVC 5.1.1 ASP.Net Razor 3.1.1 bootstrap 3.1.1 jQuery 2.1.0 json.Net 6.0.1 Web Optimization 1.1.3 Webgrease 1.6.0 etc - most new extensions, etc

I have an MVC Web app with Telerik MVC KendoUI ComboBoxFor ComboBoxes in a razor partial view:

@model HTPortal.ViewModels.ClientInquiryViewModel @using System.Web.UI.WebControls @using Kendo.Mvc.UI <div class="form-group"> @Html.LabelFor(model => model.AddressState, new { @class = "control-label col-sm-2 col-md-2 col-lg-2" }) <div class="col-sm-5 col-md-5 col-lg-5"> @(Html.Kendo().ComboBoxFor(model => model.AddressState) .Placeholder("Select Province...") .DataTextField("ProvinceName") .DataValueField("ProvinceName") .Suggest(true) .BindTo(Model.Provinces) ) </div> </div>

The data is loaded into the combobox - all ok.

In the parent razor page, after the @using (Html.BeginForm()) block, I have :

@section Scripts { <script type="text/javascript"> $(document).ready(function () { $.getJSON("http://smart-ip.net/geoip-json?callback=?", function (data) { alert(data.region); //$("#AddressCity").val(data.city); $("#AddressState").val(data.region); //$("#AddressCountry").val(data.countryName); }); }); </script> }

On the first page load, the alert does fire and I see my Province/State displayed in the alert. However, my Combobox named AddressState only get filled after I refresh the page.

I've read various other posts on similar problems but no window load or init or anything works.

Infact, in IE and Chrome - all I get is the alert dialog - the fields are never filled.

Help....

How do I get this jQuery to fill the field the FIRST time the page is called?

最满意答案

我没有正确访问Kendo UI组件...

$(document).ready(function () { $.getJSON("http://smart-ip.net/geoip-json?callback=?", function (data) { $("#AddressCity").data("kendoComboBox").value(data.city); $("#AddressState").data("kendoComboBox").value(data.region); $("#AddressCountry").data("kendoComboBox").value(data.countryName); }); });

这有效!

I didn't access the Kendo UI component correctly...

$(document).ready(function () { $.getJSON("http://smart-ip.net/geoip-json?callback=?", function (data) { $("#AddressCity").data("kendoComboBox").value(data.city); $("#AddressState").data("kendoComboBox").value(data.region); $("#AddressCountry").data("kendoComboBox").value(data.countryName); }); });

This works!

更多推荐

page,AddressState,电脑培训,计算机培训,IT培训"/> <meta name="description

本文发布于:2023-04-28 09:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:页面   但在   字段   jQuery   razor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!