[英]Submit button redirect to another view ASP.NET MVC
I want to create submit button, which redirects me to to another view when I click on Accept.我想创建提交按钮,当我单击接受时,它会将我重定向到另一个视图。
I tried this:我试过这个:
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Accept" onclick="@("window.location.href='" + @Url.Action("Index", "kupec") + "'");" class="btn btn-default"/>
</div>
</div>
And this:和这个:
<input id="#redirect" type="submit" value="Accept" class="btn btn-default" />
with JavaScript:使用 JavaScript:
$("#redirect").click(function () {
document.location = '@Url.Action("Index","Dokument")';
});
However, neither of these two is working properly.但是,这两个都不能正常工作。 What am I doing wrong?
我究竟做错了什么?
You are binding the click event to an element with Id redirect
.您正在将 click 事件绑定到 Id
redirect
的元素。 But your button id is not redirect
,but #redirect
( extra #
prefix).但是您的按钮 ID 不是
redirect
,而是#redirect
(额外的#
前缀)。 remove that and it should work.删除它,它应该可以工作。
<input id="redirect" type="submit" value="Accept" class="btn btn-default" />
Also it might be a good idea to wrap your event handlers in the document ready event.此外,将您的事件处理程序包装在文档就绪事件中可能是个好主意。 If your button is inside a form element, it is a good idea to prevent the default form submit behavior as well.( If you really don't want to submit the form, you should not keep it inside the form ! :) )
如果您的按钮位于表单元素内,最好也阻止默认的表单提交行为。(如果您真的不想提交表单,则不应将其保留在表单中!:) )
$(function(){
$("#redirect").click(function (e) {
e.preventDefault();
document.location = '@Url.Action("Index","Dokument")';
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.