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
发布评论