我在 asp.net MVC 5 网络应用程序中有一个按钮,我试图将用户重定向到 .aspx 文件。 因此,当用户点击来自asp.net MVC的按钮(该按钮的代码是HTML)时,他将被重定向到Web表单(.apsx)。 我试过这段代码,但它没有用。
<button id="Login" runat="server" OnClientClick="window.open('Login.aspx', 'Login');">Login </button>
答案 0 :(得分:0)
您必须在Action方法中调用.aspx页面。
public ActionResult Login()
{
return Redirect("~/Login.aspx");
}
答案 1 :(得分:0)
<a href="@Url.Content("~/Login.aspx")">
<button type="button">Login</button>
</a>
您可以在超链接中嵌入一个按钮,使其看起来像一个按钮,但就像一个链接。诀窍是正确设置URL。在混合Web窗体/ MVC项目中,我使用Url.Content
帮助程序,因为它尊重虚拟根目录。但是,您可以创建一个路由类。
public class WebFormsRoutes
{
public const string LoginPage = "~/Login.aspx";
}
导入适当的命名空间后,您可以执行以下操作:
<a href="@Url.Content(WebFormsRoutes.LoginPage)">
<button type="button">Login</button>
</a>
您也可以考虑查看routing documentation。您可以为友好的URL
注册自己的Web窗体路由答案 2 :(得分:-1)
您的代码看起来不像是Razor View代码。 你可以采取多种方式
1。<button onclick="window.open('Login.aspx')">Login</button>
2.使用Razor
<button onclick="location.href='@Url.Action("Login","Login")'">Login</button>
由于 帕塔