关于转向的问题,目前知道的是Response.Redirect 和 location.href
我现在有两个controller,Home和Test
<h2>this is Home</h2><p id="test">大家好,我是Vae</p><button type="button" onclick="on()">点我</button><script> ???function on() ???{ ???????alert("我转向了啊"); ????????@{ ???????????Response.Redirect("/Test/Index"); ???????} ???}</script>
Response.Redirect 这种方法呢,会直接的就转向了,那个alert没什么反应,而且貌似只能重定向到那个页面,不能返回HomeController?
这里我不明白的是没有经过我的button点击事件就执行了JavaScript代码
第二种方式比较好
<h2>this is Home</h2><p id="test">大家好,我是Vae</p><button type="button" onclick="on()">点我</button><script> ???function on() ???{ ???????alert("我转向了啊"); ???????location.href="/Test/Index"; ???}</script>
这个还是很不错的,暂且写到这里
.Net MVC个人笔记
原文地址:https://www.cnblogs.com/yunquan/p/8508789.html