2014-02-14 144 views

回答

0

單擊按鈕時是否要轉到其他頁面?

首先停止思考「頁面」,並開始思考「行動」。您無法調用或導航到ASP.NET MVC中的另一個頁面:您可以調用或導航到另一個控制器操作。 如果你有一個按鈕:

<button id="myButton">Click me</button> 

可以使用jQuery附加的單擊事件:

$("#myButton").click(function(evt) { 
    evt.preventDefault(); 
    document.location.href='@Url.Action("AnotherAction","AnotherController")'; 
}); 

(德沒有關係,如果你有一個<input type="button">而不是<button>

此代碼。將導航到AnotherController的AnotherAction。因此,如果AnotherAction返回一個視圖,該視圖將返回給瀏覽器。

希望它有幫助。 問候。

+0

我想打電話給一個頁面。在我的頁面中有一個按鈕。點擊按鈕時,我會打開一個彈出窗口。我在cshtml中創建的那個窗口。我不明白如何在不改變地址的情況下按鈕點擊打開該頁面 – user3278778

0

在MVC中,你通過HTML輔助@ Html.ActionLink

Html.ActionLink(article.Title, 
"Login", // <-- ActionMethod 
"Item", // <-- Controller Name 
new { id = article.ArticleID }, // <-- Route arguments. 
null // <-- htmlArguments .. which are none 
) 

使用構建重定向到其他意見可以說你是在\首頁\目錄,並希望重定向到另一個視圖(\首頁\ Account.cshtml) 這可以這樣完成:

@Html.ActionLink("Title", "Account", "Home") 
0
@Html.Action("ActionName", "ControllerName", new { [args] }) 
<a href="@Url.Action("ActionName", "ControllerName", new { [args] })" 

嘗試自己先找到答案,請。這是所有剃鬚刀文檔中的第一步

相關問題