Javascript 在html页面中添加主页按钮
在我的Web应用程序中,我试图在所有子页面中添加主页按钮,单击该按钮将触发Javascript 在html页面中添加主页按钮,javascript,jquery,html,asp.net-mvc,Javascript,Jquery,Html,Asp.net Mvc,在我的Web应用程序中,我试图在所有子页面中添加主页按钮,单击该按钮将触发ActionResult Index() 有什么建议吗 我只是在我的子页面DetailsForm中添加了一个按钮。在“提交”按钮旁边。在用户完成保存后,用户可以单击home按钮直接访问Index.cshtml。避免任何浏览器后退按钮。 下面的代码绝对不适合我 <input type="button" class="btn btn-lg btn-success" onclick="location.href='in
ActionResult Index()
有什么建议吗
我只是在我的子页面DetailsForm中添加了一个按钮。在“提交”按钮旁边。在用户完成保存后,用户可以单击home按钮直接访问Index.cshtml。避免任何浏览器后退按钮。
下面的代码绝对不适合我
<input type="button" class="btn btn-lg btn-success" onclick="location.href='index.cshtml';" value="Home" />
如果启用了CSS,请使用
a
标记,以便样式保持一致,然后重试
在CSS中,确保设计了button类
a.button {
-webkit-appearance: button;
-moz-appearance: button;
appearance: button;
text-decoration: none;
color: initial;
}
编辑
从您提供的错误代码来看,您很可能试图使用尚未安装或未正确安装的库。我相信你错过了可以找到的引导按钮库。如果您需要安装帮助,可以在其中找到说明。您可以在使用保存后禁用浏览器后退按钮
history.pushState(null, null, document.title);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.title);
});
然后,您可以使用按钮返回主页
<input type="button" class="btn btn-lg btn-success" onclick="goToHome()" value="Home" />
在MVC中,您导航到控件中的操作方法,而不是视图,因此您的
location.href='index.cshtml'
无法工作
例如,使用
元素重定向(如果您想要重定向,则将其样式设置为按钮)
@Html.ActionLink("Home", "Index", "Home", null, new { @class = "btn btn-lg btn-success" }
你应该使用
。尽量简化
您在MVC中不导航到.cshtml
页面-您导航到控制器中的操作方法,而只是使用@Html.ActionLink(“Home”、“Index”、“Home”、null、new{@class=“btn btn lg btn success”}创建一个链接
和its将被设置为按钮样式,因为有引导类。由于您使用默认路由(将默认控制器指定为Home
,将默认操作指定为Index
,这是应该发生的),所以主页/索引
将从url中删除。我无法猜测您的样式(问一个有相关细节的新问题)我不认为这是一个问题。我的确切代码是“你有引导按钮库吗?”location.href
似乎足够点击按钮:函数goToHome(){window.location.href=“@Url.Action(“Index”,“ControllerName”)”}
Ajax调用从不重定向!
@Html.ActionLink("Home", "Index", "Home", null, new { @class = "btn btn-lg btn-success" }