我想在单击按钮时打开新的弹出窗口,其中包含 pdf 文件。在单击按钮时,我调用了以下 jquery.在 Jquery 中,我得到了“Url”中的值。 “Url”包含以下内容
ControllerName/ViewPdf/23bbe2eh3be//编码形式的pdf路径。
但是我无法找到 Controller 中操作的路径,而不是我得到空值的路径。 现在我的问题是如何在操作中获取路径而不是接收 null?
Jquery:
function ViewPdf( url) {
var winW = 800;
var winH = 330;
var winX = (screen.availWidth - winW) / 2;
var winY = (screen.availHeight - winH) / 2;
var features = 'left=' + winX + ',top=' + winY + ',width=' + winW + ',height=' + winH + ',toolbar=0,location=0,status=0,scrollbars= 1,resizable=1';
PdfWindow = window.open(url, null, features);
}
Controller :
public ActionResult ViewPdf(String id)
{
//some Code
}
最佳答案
您应该定义此路线
routes.MapRoute("ViewPdf", "HomeController/ViewPdf/{path}", new { controller = "HomeController", action = "ViewPdf", path = UrlParameter.Optional });
你的行动:
public ActionResult ViewPdf(string path) { //some Code }
或者您应该在查询字符串中定义参数名称:
/HomeController/ViewPdf?path={your_path_here}
关于jquery - 如何通过调用window.open将值从Jquery传递到MVC Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18886647/