0

我的级联下拉框在 Visual Studio 2015 和 iisexpress 中运行良好。但是,在 IIS 上托管或在 Visual Studio 中选择 IIS 作为服务器时,不会调用填充第二个下拉框的控制器操作!我是 Javascript 的新手,对asp.net mcv我在这里使用的不是很坚定。

我用VS2015ASP.NET Mvc

创建.cshtml:

@model Bethesda2017.Models.AuftragEditViewModel

@{
    ViewBag.Title = "Neuer Reparaturauftrag";
}

<style>
    body {
        background: url(/Bilder/Bethesda4Web.jpg);
        background-position: right top;        
        background-size: 12%;
        background-repeat: no-repeat;
    }
</style>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()    

    <div class="form-horizontal body">

        <h4>Neuer Reparaturauftrag</h4>

        @Html.ValidationSummary(true, "", new { @class = "text-danger" })

-- Some irrelavant controls extracted here  ----

        <div class="form-group">
            @Html.LabelFor(model => model.STORT_ID, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @*@Html.DropDownListFor( model => model.STORT_ID, Model.StandortListe, "Bitte wählen!", new { htmlAttributes = new { @class = "form-control" } })*@
                @Html.DropDownListFor(model => model.STORT_ID, Model.StandortListe, "Bitte wählen!", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.STORT_ID, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.TRAKT_ID, htmlAttributes: new { @class = "control-label col-md-2" })
            @*@Html.DropDownListFor(model => model.TRAKT_ID, Model.TraktListe, "", new { @class = "form-control col-md-2" } )*@
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.TRAKT_ID, Model.TraktListe, "", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.TRAKT_ID, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.ETAGE_ID, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.ETAGE_ID, Model.EtageListe, "", new { @class = "form-control" } )
                @Html.ValidationMessageFor(model => model.ETAGE_ID, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.RAUM_ID, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownListFor(model => model.RAUM_ID, Model.RaumListe, "", new { @class = "form-control" } )
                @Html.ValidationMessageFor(model => model.RAUM_ID, "", new { @class = "text-danger" })
            </div>
        </div>

        @*<div class="form-group">
                @Html.LabelFor(model => model.DerAuftrag.FHD_KOMPLETT, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.DerAuftrag.FHD_KOMPLETT, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.DerAuftrag.FHD_KOMPLETT, "", new { @class = "text-danger" })
                </div>
            </div>*@


        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Speichern" class="btn btn-default" />
            </div>
        </div>
    </div>
}
<!-- JS includes -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/mvc/4.0/jquery.validate.unobtrusive.min.js"></script>

<script type="text/javascript">
    var trakt_idUrl = '@Url.Action("FetchTrakte", "Auftrag")';
    var trakte = $('#TRAKT_ID');
    var etage_idUrl = '@Url.Action("FetchEtagen", "Auftrag")';
    var etagen = $('#ETAGE_ID');
    var raume = $('#RAUM_ID');
    var raum_idUrl = '@Url.Action("FetchRaume", "Auftrag")';
    $('#STORT_ID').change(function () {
        trakte.empty();
        etagen.empty();
        raume.empty();
        $.getJSON(trakt_idUrl, { STORT: $(this).val() }, function (data) {
            if (!data)
            { return; }
            trakte.append($('<option></option>').val('').text('Bitte Trakt wählen!'));
            $.each(data, function (index, item) {
                trakte.append($('<option></option>').val(item.TRAKT_ID).text(item.BEZEICHNUNG));
            })
        }
        )
    }
    )

    $('#TRAKT_ID').change(function () {
        etagen.empty();
        raume.empty();
        $.getJSON(etage_idUrl, { STORT: $(this).val() }, function (data) {
            if (!data)
            { return; }
            etagen.append($('<option></option>').val('').text('Bitte Etage wählen!'));
            $.each(data, function (index, item) {
                etagen.append($('<option></option>').val(item.ETAGE_ID).text(item.BEZEICHNUNG));
            })
        }
        )
    }
    )

    $('#ETAGE_ID').change(function () {
        raume.empty();
        $.getJSON(raum_idUrl, { STORT: $(this).val() }, function (data) {
            if (!data)
            { return; }
            raume.append($('<option></option>').val('').text('Bitte Raum wählen!'));
            $.each(data, function (index, item) {
                raume.append($('<option></option>').val(item.RAUM_ID).text(item.BEZEICHNUNG));
            })
        }
        )
    }
    )

</script>

在第一个下拉框中选择一个条目时,java 脚本 $('#STORT_ID').change(function () ... 被调用并且 trakte、etagen 和 raume 设置为空,但下一步:$.getJSON(trakt_idUrl , { STORT: $(this).val() }, function (data) {... 应该调用方法

public JsonResult FetchTrakte(string STORT )        
        {
            List<Trakt> _l = FetchTrakteList(STORT);

            if ( _l.Count<1 )
            {
                Trakt _s0 = new Trakt() { TRAKT_ID = "00", BEZEICHNUNG = "keine Daten" };
                _l.Add(_s0);
            }

            return Json(_l, JsonRequestBehavior.AllowGet);
        }

仅在使用时调用,iisexpress但不与 IIS 一起调用!

问题出在哪里或如何检查这里发生了什么?

4

0 回答 0