I have an input button and I want to redirect to a view or action when it's clicked. How can I do this?
+1
A:
Can you not just specify the appropriate URL for the action of the form that the button is part of?
Jon Skeet
2010-08-29 17:07:44
A:
I just realized that the input button needed to go to a different url that I can map with a link.
Carl Weis
2010-08-29 17:14:54
+1
A:
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.
Darin Dimitrov
2010-08-29 18:37:59