【问题标题】:MVC5 and IIS 7.5 ConfigurationMVC5 和 IIS 7.5 配置
【发布时间】:2016-08-26 07:52:54
【问题描述】:

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

<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 when devug

有什么建议可以解决这个问题吗?

【问题讨论】:

  • 我认为这与配置无关。验证您的网址。 /Audit/FindSubCode 将指向服务器的根目录,这可能是应用程序所在的不同路径。尽量不要对路径进行硬编码,而是使用 razor 生成路径。即@(Url.Action("FindSubCode","Audit")

标签: asp.net-mvc-5 iis-7.5


【解决方案1】:

我认为这与配置无关。验证您的网址。

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

尽量不要硬编码路径,而是使用 razor 引擎UrlHelper 生成路径。

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

【讨论】:

    猜你喜欢
    • 2014-08-04
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 1970-01-01
    • 2011-11-11
    • 2010-12-09
    相关资源
    最近更新 更多