The management of user actions MVC is different then in ASP.NET.
Lets explain by using an example, supposing that from the user want to activate the Édit page by using a link or a button from Index page.
1.In response to the user action there must be a method in controller (that will be invoked from the client by using GET) named
ViewResult Edit()
that are used to create the Model and to return the
ViewResult
that will render the view and send it to the client browser. So this Edit() method is invoked only for the first GET (similar with IsPostback equal with false)!
2.Then the browser will show the Edit view (page) and the user will can use some controls that collect the user inputs and finally press
Save
submit button, that first will activate the client side validation and then, if the client side validation will succeed, it will generate a postback to the server.
3.On you controller there should exist 2nd method with the same name
ActionResult Edit(EditModel model)
but they should have some parameter (usually the model object used) and this method must have
[HttpPost]
attribute specified, and this method will be invoked from the client in 2nd step above. This method normally should made some logical validation of the entire user inputs, then try to save the input data into the database, also should manage the possible errors (so different actions results could be generated from its code).
You can see example in my next article:
MVC Basic Site: Step 1 – Multilingual Site Skeleton[
^]