3

I have an input button and I want to redirect to a view or action when it's clicked. How can I do this?

3 Answers 3

3

You can't redirect to a view. You could redirect to a controller action which in turn will render a view. You could do it using javascript:

<input type="button" id="foo" value="foo" />

and once the DOM is loaded attach a click event:

$(function() {
    $('#foo').click(function() {
        window.location.href = '<%= Url.Action("foo") %>';
    });
});

If you are talking about a submit button then you don't need javascript, simply set the action of the associated form:

<% using (Html.BeginForm("actionName", "controllerName")) { %>
    <input type="submit" value="foo" />
<% } %>

But I think that in your situation the most semantically correct is to simply use an anchor tag which you could style with CSS to look as a button.

Sign up to request clarification or add additional context in comments.

Comments

2

Can you not just specify the appropriate URL for the action of the form that the button is part of?

Comments

0

I just realized that the input button needed to go to a different url that I can map with a link.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.