单击按钮时如何重定向用户?
问题描述:
我有一个带按钮的视图.当用户单击按钮时,我希望他们重定向到数据输入视图.我该如何完成?我应该提到这些视图是创建,测试和运行的.我可以通过输入网址来找到他们.
I have a view with a button. When the user clicks the button I want them redirected to a data entry view. How do I accomplish this? I should mention the views are created, tested, and functioning. I can get to them by typing the url.
我在寻找解释如何连接按钮onclick事件的步骤,但是我对MVC并不陌生,在这一点上有点迷茫.
I looked for steps explaining how to wire up the onclick event of the button but I'm new to MVC and kinda lost at this point.
谢谢!
答
这取决于您所说的按钮含义.如果是链接:
It depends on what you mean by button. If it is a link:
<%= Html.ActionLink("some text", "actionName", "controllerName") %>
要发布,您可以使用以下表格:
For posting you could use a form:
<% using(Html.BeginForm("actionName", "controllerName")) { %>
<input type="submit" value="Some text" />
<% } %>
最后还有一个按钮:
<input type="button" value="Some text" onclick="window.location.href='<%= Url.Action("actionName", "controllerName") %>';" />