Using Our Models

Take a look at AddPost function.

Instead of specifying a parameter for each request form field that we need to capture, we can simply use a parameter of type entry named entry.

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

Then, our Add function could be like this.

public ActionResult Add()
{
    var entry = new Entry()
    {
        Date = DateTime.Today
    };

    return View(entry);
}

Now, let's code in the View class using strongly typed view.

@model Treehouse.FitnessFrog.Models.Entry

Then, we should update our HTML tags to use our model.

// before
@Html.Label("Date", null, new { @class = "control-label"})
@Html.TextBox("Date", null, new { @class = "form-control"})

// after
@Html.LabelFor(m => m.Date, new { @class = "control-label"})
@Html.TextBoxFor(m => m.Date, new { @class = "form-control"})

results matching ""

    No results matching ""