Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url.Action only render controller and action but not id

I need to render a URL for a JavaScript search that I am doing. Unfortunately Url.Action renders not only the action but the current id. This occurs when presently on page utilizing the action with the id.

To illustrate Url.Action("List", "Org"); will first render Org/List from which I can append an org to be listed. However, after the location has been moved to Org/List/12345 Url.Action("List", "Org"); will render Org/List/12345 and appending to that creates an issue where I end up with Org/List/12345/6789.

Is there a different method I can use other than Url.Action? I've thought about using JavaScript to check for the number of / and removing part of the string but that seems a bit hackish.

// appears in my Site.Master & utilizes the AutoComplete plugin for jQuery
$(document).ready(function() {
    $("input#FindOrg").autocomplete('<%= Url.Action("Find", "Org") %>', {
        minChars: 3,
        maxItemsToShow: 25
    }).result(function(evt, data, formatted) {
        var url = '<%= Url.Action("List", "Org") %>/';
        window.location.href = url + data;
    });
});
like image 576
ahsteele Avatar asked Jan 18 '10 19:01

ahsteele


1 Answers

Couple of suggestions:

What happens if you use Url.Action("Find", "Org", new { id = "" })?

Alternately, try manually building the url with Url.Content("~/Find/Org").

like image 114
womp Avatar answered Oct 07 '22 23:10

womp