2014-02-14 53 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] })" 

尝试自己先找到答案,请。这是所有剃须刀文档中的第一步

相关问题