Mvc下拉列表在本地工作,但在发布到azure服务器时不能 [英] Mvc dropdown works locally but not when published to azure server

查看:53
本文介绍了Mvc下拉列表在本地工作,但在发布到azure服务器时不能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有模式弹出窗口的视图,其中包含一个下拉列表。当我在本地IIS服务器上测试页面正常运行但当我将页面发布到Azure服务器时,下拉列表不会填充。



这是对我的观点:

< label class =control-label col-md-2> 
客户
< / label>
< div class =col-md-8>
< select id =customername =customerclass =form-control>
< option> Customer< / option>
< / select>





这是剧本:

 //加载客户下拉列表
var NCustomers = []
函数LoadCustomer(element){
if(NCustomers.length === 0){
// ajax函数for fetch data
$ .ajax({
type:GET,
url:'/ NYCHWebApp / PendingOrders / GetCustomers',//'@ Url.Action(GetCustomers, PendingOrders)',
成功:函数(数据){
NCustomers = data;
//渲染客户
renderCustomers(element);
}
})
}
else {
//将客户呈现给元素
renderCustomers(element);
}
}

函数renderCustomers(element){
var $ ele = $(element);
$ ele.empty();
$ ele.append($('< option />').val('0').text('Select'));
$ .each(NCustomers,function(i,val){
$ ele.append($('< option />').val(val.CustomerName).text(val.CustomerName) ));
})
}







这是方法控制器:

 public JsonResult GetCustomers()
{
List< Customer> NYHCCustomers =新名单< Customer>();
//使用(MyDatabaseEntities dc = new MyDatabaseEntities())
{
NYHCCustomers = db.Customers.OrderBy(a => a.CustomerName).ToList();
}
返回新的JsonResult {Data = NYHCCustomers,JsonRequestBehavior = JsonRequestBehavior.AllowGet};
}





我的尝试:



我将脚本放在一个文件中并将其移动到视图但没有改变。问题似乎在于对控制器的调用。

解决方案

.ajax({
type:GET,
url:' / NYCHWebApp / PendingOrders / GetCustomers',//'@ Url.Action(GetCustomers,PendingOrders)',
成功:函数(数据){
NCustomers = data;
/ / render customers
renderCustomers(element);
}
})
}
else {
//将客户呈现给元素
renderCustomers (元件);
}
}

函数renderCustomers(element){
var


ele =


(元件);

I have a view with a modal popup which contains a dropdown list. When I test on my local IIS server the page functions correctly but when I publish the page to an Azure server the dropdown list does not populate.

This is the control on my view:

<label class="control-label col-md-2">
                    Customer
                </label>
                <div class="col-md-8">
                    <select id="customer" name="customer" class="form-control">
                        <option>Customer</option>
                    </select>



This is the script:

//Load Customer Drop Down list
    var NCustomers = []
    function LoadCustomer(element) {
    if (NCustomers.length === 0) {
    //ajax function for fetch data
    $.ajax({
    type: "GET",
    url: '/NYCHWebApp/PendingOrders/GetCustomers', // '@Url.Action("GetCustomers", "PendingOrders")',
    success: function (data) {
    NCustomers = data;
    //render customers
    renderCustomers(element);
    }
    })
    }
    else {
    //render customer to the element
    renderCustomers(element);
    }
    }

    function renderCustomers(element) {
    var $ele = $(element);
    $ele.empty();
    $ele.append($('<option />').val('0').text('Select'));
    $.each(NCustomers, function (i, val) {
    $ele.append($('<option />').val(val.CustomerName).text(val.CustomerName));
    })
    }




This is the method in the controller:

public JsonResult GetCustomers()
        {
            List<Customer> NYHCCustomers = new List<Customer>();
            //using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                NYHCCustomers = db.Customers.OrderBy(a => a.CustomerName).ToList();
            }
            return new JsonResult { Data = NYHCCustomers, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }



What I have tried:

I had the script in a file and moved it to the view but did not change. The problem seems to be in the call to the controller.

解决方案

.ajax({ type: "GET", url: '/NYCHWebApp/PendingOrders/GetCustomers', // '@Url.Action("GetCustomers", "PendingOrders")', success: function (data) { NCustomers = data; //render customers renderCustomers(element); } }) } else { //render customer to the element renderCustomers(element); } } function renderCustomers(element) { var


ele =


(element);


这篇关于Mvc下拉列表在本地工作,但在发布到azure服务器时不能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆