C# 在MVC中启动新的aspx页面时如何传递参数
我正在尝试启动一个新的预览页面,为此,我尝试在单击图像时调用它。我还需要将一个ID作为参数传递给新页面我想在C# 在MVC中启动新的aspx页面时如何传递参数,c#,html,asp.net,asp.net-mvc,C#,Html,Asp.net,Asp.net Mvc,我正在尝试启动一个新的预览页面,为此,我尝试在单击图像时调用它。我还需要将一个ID作为参数传递给新页面我想在public ActionResult Index方法中接收它。这是我试过的代码 来自parents index.aspx <a href="#" onclick="openWindow('Preview/Index.aspx?ID = 12344');"><img style="border:0;" src="/Content/Images/approveIcon.pn
public ActionResult Index
方法中接收它。这是我试过的代码
来自parents index.aspx
<a href="#" onclick="openWindow('Preview/Index.aspx?ID = 12344');"><img style="border:0;" src="/Content/Images/approveIcon.png" alt="HTML try" width="20" height="20" /></a>
<script language='Javascript'>
<!--
// Function to open new window containing window_src, 100x400
function openWindow(window_src) {
window.open(window_src, 'newwindow', config = 'height=100, width=400, '
+ 'toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, '
+ 'directories=no, status=no');
}
-->
</script>
我遇到资源丢失错误,如何启动新的预览窗口并将ID作为参数传递给index方法?我希望它能帮助:
在你的链接中
<a href="#" onclick="openWindow(@Url.Action("Index", "Preview", new { id = "1234" });"><img style="border:0;" src="/Content/Images/approveIcon.png" alt="HTML try" width="20" height="20" /></a>
在你的剧本里
<script language='Javascript'>
<!--
// Function to open new window containing window_src, 100x400
function openWindow(window_src) {
var path = window.location.pathname + window_src;
alert(path);//So you can see the full path
window.open(path , 'newwindow', config = 'height=100, width=400, '
+ 'toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, '
+ 'directories=no, status=no');
}
-->
}
使用fiddler或浏览器“开发人员工具”中的“网络”选项卡,检查要打开的url。这可能是一个错误的URL。我不明白你的语法。window.location.pathname是什么?我需要把它放在哪里,你能简单地告诉我吗,我是新手,在url前面使用“/”,比如“/Preview/Index.aspx?ID=12344”,参数和值之间没有空格。嗨,我在IE中遇到错误,比如“消息:条件编译已关闭”。而且页面仍然没有打开。是否可以在窗口之前使用警报(路径)
。打开以便查看路径
<script language='Javascript'>
<!--
// Function to open new window containing window_src, 100x400
function openWindow(window_src) {
var path = window.location.pathname + window_src;
alert(path);//So you can see the full path
window.open(path , 'newwindow', config = 'height=100, width=400, '
+ 'toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, '
+ 'directories=no, status=no');
}
-->
function openWindow(srcid) {
$.ajax({
url: 'Preview/Index',
type: "POST",
dataType: "json",
data: { ID: 12344},
success: function (data) {
alert(error.toString());
},
error: function (error) {
alert(error.toString());
}
});
<a href="#" onclick="openWindow();"><img style="border:0;" src="/Content/Images/approveIcon.png" alt="HTML try" width="20" height="20" /></a>