在我的 MVC _layout 页面上,我有一个按钮可以下拉一个带有 iframe 的面板。它使用 C# 和 Razor
我想用另一个 html 页面的内容填充 iframe,以显示当前屏幕的帮助,格式如 ControllerNameActionNameHelp.html。
如何获取 Ajax 调用的当前 Controller 名称和操作名称?
(或者这样做的方式不对?)
最佳答案
在c#中可以通过多种方式获取当前页面请求url。
HttpContext.Current.Request.Url.AbsolutePath
表格的网址:http://host/controllername/methodname .然后你可以使用 c# 分解它。获取 Controller 和方法名称段。现在使用它,您可以将 ajax 调用发送到所需的 Controller 方法。
$("button").click(function(){
$.ajax({
url: "../ControllerName/ActionName",
success: function(result){
$("#div1").html(result);
}
error: function(e){
alert(e);
}
});
});
关于jquery - 使用 Controller 和 Action 名称进行 ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30419911/