@{Response.Redirect("Index","Home")};
上述代码不起作用,请帮助我。
Response.Redirect
是服务器端操作,在视图中使用毫无意义。您正在追随适当的客户端操作。
您只需在JavaScript(客户端端)中更改window.location.href
即可重定向浏览器,然后使用Url.Action
在JavaScript中生成(服务器端)适当的客户端URL。
例如。类似:
<input type="button" onclick="function(){window.location.href=@(Url.Action("Index", Home"))}" value="Press Me!"/>
坦率地说,您可能只需要一个看起来像按钮的链接,因为在这种情况下使用location.href
重定向没有优势。