Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect a user when a button is clicked?

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.

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.

Thanks!

like image 566
DenaliHardtail Avatar asked Jul 02 '10 19:07

DenaliHardtail


People also ask

How do I redirect a URL to another user?

Approach: To redirect from an HTML page to another page, you can use the <meta> tag by specifying the particular link in the URL attribute. It is the client-side redirection, the browsers request the server to provide another page.

How do I automatically redirect a URL?

To redirect from an HTML page, use the META Tag. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value of the content is the number of seconds; you want the page to redirect after.

How do I redirect one page to another in HTML?

How to Redirect to Another Page in HTML. To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.


2 Answers

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" /> <% } %> 

And finally if you have a button:

<input type="button" value="Some text" onclick="window.location.href='<%= Url.Action("actionName", "controllerName") %>';" /> 
like image 72
Darin Dimitrov Avatar answered Sep 25 '22 15:09

Darin Dimitrov


Just as an addition to the other answers, here is the razor engine syntax:

<input type="button" value="Some text" onclick="@("window.location.href='" + @Url.Action("actionName", "controllerName") + "'");" /> 

or

window.location.href = '@Url.Action("actionName", "controllerName")'; 
like image 20
AGuyCalledGerald Avatar answered Sep 23 '22 15:09

AGuyCalledGerald