Url.Action只会使控制器和动作,而不是ID [英] Url.Action only render controller and action but not id
问题描述
我需要渲染为我做一个JavaScript搜索的URL。不幸的是 Url.Action
渲染不仅是行动,但当前ID。这发生在presently利用id为动作页面上。
要说明 Url.Action(列表,组织);
将首先呈现组织/列表
从中我可以追加一个组织上市。但是,在位置已经移动到组织/列表/ 12345
Url.Action(列表,组织);
将呈现组织/列表/ 12345
并追加到创建,我结束了组织/问题列表/六千七百八十九分之一万二千三百四十五
。
是否有不同的方法,我可以用比 Url.Action
其他?我已经考虑过使用JavaScript来检查 /
的数量和字符串的一部分去除,但似乎有点hackish的。
//出现在我的Site.Master&安培;利用自动完成的jQuery插件
$(文件)。就绪(函数(){
$(#输入FindOrg)自动完成('<%= Url.Action(查找,组织)%GT;',{
minChars:3,
maxItemsToShow:25
})。结果(函数(EVT,数据格式){
VAR URL ='<%= Url.Action(列表,组织)%GT; /';
window.location.href =网址+数据;
});
});
的建议夫妇:
如果您使用 Url.Action(查找,组织,新{ID =})
?
另外,尽量手动构建URL以 Url.Content(〜/查找/组织)
。
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;
});
});
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")
.
这篇关于Url.Action只会使控制器和动作,而不是ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!