如何在MVC中启动新的aspx页面时传递参数

时间:2014-04-16 05:53:10

标签: c# html asp.net asp.net-mvc

我正在尝试启动一个新的预览页面,因为我在点击图片时试图打电话。而且我还需要将ID作为参数传递给新页面。 &安培;我想用public ActionResult Index方法接收它。这是我试过的代码。

来自父母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>

这是我的新预览控制器类

public class PreviewController : Controller
{
    //
    // GET: /Preview/

    public ActionResult Index(String ID)
    {
        return View();
    }

}

我遇到资源缺失错误,如何启动新预览窗口并将ID作为参数传递给索引方法?

2 个答案:

答案 0 :(得分:0)

我希望它会有所帮助: 在你的链接

<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');
  }
-->

答案 1 :(得分:0)

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>
相关问题