I need to create a page that has the equivalent to button click event in ASP.NET.
On my page when the user clicks a button I need to process some information and if an error occured then display an Error page, but if it was successful I need to display a successful page. I’m new at MVC and I’m not sure how to go about this…
This is what I’ve came up with so far (don’t know if this will even work), I would create an ActionResult function to process the information then have the function decide which page should be displayed…
'//Foo page
Function Foo(Byval param1 as String, Byval param2 as String) As ActionResult
Return View()
End Function
Function FooProcess(Byval param1 as String, Byval param2 as String) As ActionResult
'//Look up information and process
'//bSuccess = process(param1, param2)
'//If bSuccess Then
'// redirect to successful page
'//else
'// redirect to error page
'//end if
End Function
Function FooSuccessful() As ActionResult
Return View()
End Function
Function FooError(ByVal msg As String) As ActionResult
Return View()
End Function
you need to use [AcceptVerbs(HttpVerbs.Post)] and [AcceptVerbs(HttpVerbs.Get)] attributes to distinguish between normal and posted back page as for example here:
http://blog.jorritsalverda.nl/2010/03/10/maintainable-mvc-post-redirect-get-pattern/