Using Model Binding

We just added an action method to process form post for the Add path. Now, we are ready to capture our Request data.

Set a breakpoint in AddPost's return line of code. Then, run the project.

Take a look at Autos window > Expand "this" > Request > Form. Now, we want to get the form's input.

We could declare a new variable to get those input.

[ActionName("Add"), HttpPost]
public ActionResult AddPost()
{
    string date = Request.Form["Date"];

    return View();
}

Using method above would require lot of lines to declare other parameters. Luckily, .NET provides us much simpler way.

[ActionName("Add"), HttpPost]
public ActionResult AddPost(string date, string activityId, 
    string duration, string intensity, string exclude, string notes)
{
    return View();
}

Now, take a look at your Autos window. This method called Model Binding.

results matching ""

    No results matching ""