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
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.