簡體   English   中英

如何在MVC中啟動新的aspx頁面時傳遞參數

[英]How to pass parameter in launching new aspx page in 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作為參數傳遞給索引方法?

希望對您有所幫助:在您的鏈接中

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM