简体   繁体   中英

Controller action being hit twice MVC

I have an imagelink extension that i am using to navigate to another view. Once the user chooses a value from a dropdown list and clicks the link, i need to navigate to the next view and pass the value of their selection. Everything is working, except for the action i am passing to is being hit twice. I cannot seem to wrap my head around why this is happening.

View

<div class="locationSelection">
@(Html.Kendo().DropDownList()
.Name("locationList")
.DataTextField("DisplayName")
.DataValueField("LocationCode")
.BindTo(Model)
.OptionLabel(new { DisplayName = "Select Your Location....", LocationCode = "NA" })
)
</div>
<div id="userSelection">
<div id="currentQueue">
    @Html.ImageLink("/Images/CurrentPickups.jpg", "Search", "Search", "Manage Current Pickups")
</div>

<div id="previousSubmissions">
    @Html.ImageLink("/Images/PreviousSubmissions.jpg", "Search", "searchPrevious", "Search Previous Pickups")
</div>
<div>
    &nbsp;
</div>
</div>
<script type="text/javascript">
$("#userSelection a").click(function (e) {
    e.preventDefault();
    var href = $(this).attr('href');
    var dropdownlist = $("#locationList").data("kendoDropDownList");
    if (dropdownlist.value() != "NA") {
        var route = href + "?locationCode=" + dropdownlist.value();
        window.location.href = route;
    } else {

        alert("A valid location must be selected!");
    }
});
</script>

The target view had the exact same imagelink in it as the one i was clicking. Im not sure why that caused the action to be hit twice, but removing it resolved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM