javascript - Url.Action only render controller and action but not id - Stack Overflow

I need to render a URL for a JavaScript search that I am doing. Unfortunately Url.Action renders not on

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").autoplete('<%= Url.Action("Find", "Org") %>', {
        minChars: 3,
        maxItemsToShow: 25
    }).result(function(evt, data, formatted) {
        var url = '<%= Url.Action("List", "Org") %>/';
        window.location.href = url + data;
    });
});

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").autoplete('<%= Url.Action("Find", "Org") %>', {
        minChars: 3,
        maxItemsToShow: 25
    }).result(function(evt, data, formatted) {
        var url = '<%= Url.Action("List", "Org") %>/';
        window.location.href = url + data;
    });
});
Share Improve this question edited Jan 18, 2010 at 19:33 ahsteele asked Jan 18, 2010 at 19:19 ahsteeleahsteele 26.5k28 gold badges138 silver badges253 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 12

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").

You could 'cheat' and access the 'Controller' and 'Action' entries in the Routing Dictionary. This would then allow you to construct only the part of the url you need. The only caveat is that if you change your routing model these routines may bee incorrect.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743761604a4502733.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信