Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Morten Uldum 1 post 71 karma points
    Jul 09, 2019 @ 09:56
    Morten Uldum
    0

    All partial views in switch statement rendered, and not the selected value.

    I have a small problem. I have some html select markup, when on change I need to render a partial view based on the select statement. I have a switch case in some javascript, but what happens when I load the page, both Html.Paritials are being rendered. The partials are created in the backoffice.

    my code looks like this:

    //My attempt at the function for the rendering of partials    
    function SendMail() {
        var select = document.getElementById("foo");
        var selected = select.options[select.selectedIndex].value;
    
        console.log("Test")
    
        switch (selected) {
            case '0':
                break;
            case '1':
                alert(selected)
                @*$.ajax({ url: @Url.Action("Web/Partial1", @Model.Boo)})*@
                break;
            case '2':
                alert(selected)
                @*$.ajax({ url: @Url.Action("Web/Partial2", @Model.Boo)})*@
                break;
        }
    }  
    

    And the html markup looks like this:

                            <select class="col-sm-6 text-sm-left" id="foo" onchange="SendMail()">
                                <option value="0" selected="selected">Vælg en type</option>
                                <option value="1">Ordrebekræftigelse</option>
                                <option value="2">Betalingsmail</option>
                            </select>
    

    But both of the partials in the switch statement are being rendered, but the alert and test log is not compiled, but if the ajax calls are commented out, then they are compiled as expected.

    ps. I need to add, that the 2 partial views is working as handlers, which when rendered sends an email, so there is no actual view to be shown. But what happens is that both mails are being send as soon as the page is loaded.

Please Sign in or register to post replies

Write your reply to:

Draft