Last post May 13, 2013 11:03 PM by AppDevForMe
May 12, 2013 11:07 PM|AppDevForMe|LINK
I need to place an MVC style button on a view page. When the website user clicks on the button, it will redirect to a different view page.
How can I do this? Suppose that the view/page to redirect to is named "ContactInformation". So then I would have a controller method named "ContactInformation". So how would I create such a button on the first view page? I was thinking about something like
this, however I don't beleive that it is correct :
<input type="submit" class="test" value="Next" name="depreciation" />
May 12, 2013 11:28 PM|CPrakash82|LINK
How can I do this? Suppose that the view/page to redirect to is named "ContactInformation". So then I would have a controller method named "ContactInformation".
In MVC we don't redirect to view but controller and action, if you are just trying to navigate then use <a> anchor tag.
May 13, 2013 01:07 AM|Mubashir Qureshi|LINK
You can use jquery to to do this efficiently
var url = '@Url.Action("Action", "Controller")';
window.location.href = url;
May 13, 2013 09:05 AM|AppDevForMe|LINK
Thank you. Jquery is cool. I would like to use the type of button control I posted above if that is possible.
May 13, 2013 09:18 AM|Rion Williams|LINK
You can easily just wrap a normal button within an <a> tag to handle this functionality. Using the
Url.Action() HTML Helper will allow you to target the Controller Action that you desire :
<a href='@Url.Action("YourAction", "YourController")'>
<input type='button' value='Dummy Button' />
<input type='button' value='Dummy Button' onclick='window.location = "@Url.Action("YourAction", "YourController")";' />
May 13, 2013 11:03 PM|AppDevForMe|LINK
Thank you Rion, works nicely.