2016-08-26 108 views
0

我有虚拟服务器在哪里配置IIS 7.5与ASP.NET MVC一起使用。 当我部署应用程序时,一切正常。当我运行应用程序时,只有一件事不起作用,也许我错了,但我认为代码是正确的。MVC5和IIS 7.5配置

<script> 
$(document).ready(function() { 
    $("#Subcode").prop("disabled", true); 
    $("#MasterId").change(function() { 
     if ($("#MasterId").val() != "Select Master Code") { 
      var CountryOptions = {}; 
      CountryOptions.url = "/Audit/FindSubCode"; 
      CountryOptions.type = "POST"; 
      CountryOptions.data = JSON.stringify({ master_id: $("#MasterId").val() }); 
      CountryOptions.datatype = "json"; 
      CountryOptions.contentType = "application/json"; 
      CountryOptions.success = function (SubCodeList) { 
       $("#Subcode").empty(); 
       for (var i = 0; i < SubCodeList.length; i++) { 
        $("#Subcode").append("<option>" + SubCodeList[i] + "</option>"); 
       } 
       $("#Subcode").prop("disabled", false); 
      }; 
      CountryOptions.error = function() { alert("Error in Getting SubCodes!!"); }; 
      $.ajax(CountryOptions); 
     } 
     else { 
      $("#Subcode").empty(); 
      $("#Subcode").prop("disabled", true); 
     } 
    }); 
}); 
</script> 

@Html.DropDownList("MasterId",ViewBag.MasterId as SelectList,"Select Master Code",new { @class = "form-control"}) 
<select id="Subcode"></select> 

而且从控制器

public JsonResult FindSubCode(int master_id) 
{ 
    List<string> SubCodeList = new List<string>(); 
    switch(master_id) 
    { 
     case 1: 
      SubCodeList.Add("Test"); 
      break; 
     case 2: 
      SubCodeList.Add("Test2"); 
      break; 
    } 
    return Json(SubCodeList); 
} 

代码为什么我在写这问题,因为IIS配置,因为如果我在本地运行该应用程序,一切工作正常。但是,当我在服务器上运行时,出现错误代码“Error in Getting SubCodes !!”。

我试图调试,并得到一个错误:Error when devug

任何建议,我怎么能解决这个问题?

+0

我不认为它与配置有关。验证您的网址。 '/ Audit/FindSubCode'将指向服务器的根目录,该目录可能与应用程序的服务位置不同。尽量不要硬编码路径,而是使用剃须刀来生成路径。即'@(Url.Action(“FindSubCode”,“审计”)' – Nkosi

回答

0

我不认为它与配置有关。验证您的网址。

/Audit/FindSubCode将指向服务器的根目录,该服务器可能是应用程序从其服务的不同路径。

尽量不要硬编码路径,而是使用剃须刀工程UrlHelper来生成路径。

CountryOptions.url = "@(Url.Action("FindSubCode","Audit")";