简体   繁体   English

ASP.NET MVC4如何转到另一页上的模式

[英]ASP.NET MVC4 How to go to and open modal on another page

I currently have two pages and I want to find a way to link from one page to my other page and have the modal open. 我目前有两页,我想找到一种方法将一个页面链接到另一页并打开模式。 The Javascript function on the page that has the modal is triggered by an click event handler from a button with an id on the same page. 具有模式的页面上的Javascript函数由同一页面上具有ID的按钮的click事件处理程序触发。 Is there some way I could use the HTMLHelper @Html.ActionLink() method to solve this? 有什么办法可以使用HTMLHelper @ Html.ActionLink()方法解决此问题? I have looked at the overloads but I cannot seem to find one that will work with this. 我已经看了重载,但似乎找不到能解决此重载的重载。 I currently have the following Javascript which works, but I was wondering if there was an alternative solution to this. 我目前有下面的Javascript有效,但是我想知道是否有替代的解决方案。

`var hash = window.location.hash;
    if (hash == "#login") {
        toggleOverlay();
    }`

It won't be as pretty as just using the @Html.ActionLink() but you can simply create your own link as follows: 它不会像使用@ Html.ActionLink()那样漂亮,但是您可以按如下所示简单地创建自己的链接:

<a href="@(Url.Action("[ActionName]", "[ControllerName]"))/#login">Login</a>

Alternatively you can most definitely create your own HTML Helper that will you can use to generate the above. 另外,您绝对可以创建自己的HTML Helper,将其用于生成上述内容。 Please let me know if you want example code for that I will gladly help. 如果您需要示例代码,请告诉我,我们将竭诚为您服务。

UPDATE: 更新:

It appears that a little bit of research would be good! 似乎进行一点点研究会很好! After I posted this answer, I found that there is in-fact an overload that handles this directly. 发布此答案后,我发现实际上存在直接处理此问题的重载。 It is called the Fragment parameter of the ActionLink. 它称为ActionLink的Fragment参数。 Enjoy! 请享用!

Html.ActionLink("Link Text", "ActionName", "ControllerName", null, null, "login", null, null)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM