Handling a Form Post

Actually, we don't have an action to process the input of the form in our controller class.

We already have Add function to generate View when Add button being pressed from Homepage. But, how with function to process the user's input?

We could create a new function to take care of it.

public ActionResult AddPost()
{

}

However, it doesn't have correspondent view to this function.

We can simply label or decorate our code with attibutes.

[ActionName("Add"), HttpPost]
public ActionResult AddPost()
{
    return View();
}

Add breakpoint to return value in both of functions.

Having separate action methods for Get and Post requests will help keep our code clean and more maintainable.

Controller has an ability to get the information about the current request, includin HTTP method.

So, we can set a simple logic to check whether current request is POST or not.

Go to Add function in Controller class.

results matching ""

    No results matching ""