You are not subscribing to any success callback in your $.post AJAX call.(您没有在$ .post AJAX调用中订阅任何成功回调。)
Meaning that the request is executed, but you do nothing with the results.(这意味着该请求已执行,但是您对结果不执行任何操作。) If you want to do something useful with the results, try:(如果您想对结果做一些有用的事情,请尝试:)
$.post('/Branch/Details/' + id, function(result) {
// Do something with the result like for example inject it into
// some placeholder and update the DOM.
// This obviously assumes that your controller action returns
// a partial view otherwise you will break your markup
});
On the other hand if you want to redirect, you absolutely do not need AJAX.(另一方面,如果要重定向,则绝对不需要AJAX。) You use AJAX only when you want to stay on the same page and update only a portion of it.(仅当您希望停留在同一页面上并仅更新其中一部分时,才使用AJAX。)
So if you only wanted to redirect the browser:(因此,如果您只想重定向浏览器:)
function foo(id) {
window.location.href = '/Branch/Details/' + id;
}
As a side note: You should never be hardcoding urls like this.(附带说明:绝对不要这样对URL进行硬编码。) You should always be using url helpers when dealing with urls in an ASP.NET MVC application.(在ASP.NET MVC应用程序中处理URL时,应始终使用URL帮助器。) So:(所以:)
function foo(id) {
var url = '@Url.Action("Details", "Branch", new { id = "__id__" })';
window.location.href = url.replace('__id__', id);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…