0

My cascading drop down box work fine from within visual studio 2015 and iisexpress. But when hosting on IIS or selecting IIS as server in visual studio the controller action to populate the second drop drown box is not called! I'm new to Javascript and and not very firm with asp.net mcv with I use here.

I use VS2015, ASP.NET Mvc

Create.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>

When selecting an entry in the first drop down box the java script $('#STORT_ID').change(function () ... gets called and trakte, etagen and raume are set empty but the next step: $.getJSON(trakt_idUrl, { STORT: $(this).val() }, function (data) {... which should call the method

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);
        }

is only called when using iisexpress but not with IIS!

Where is the problem or how to examine what is going on here?

Nisarg
  • 1,631
  • 6
  • 19
  • 31
Joerg
  • 1
  • Post only the relevant part of the code to the question. you can exclude your CSS definition etc. Also format your code so that people can read it easily. – Shyju Oct 21 '17 at 14:44
  • ok, you are right. The next time.... – Joerg Oct 21 '17 at 17:37

0 Answers0