1 00:00:00,320 --> 00:00:04,280 Let's update our web app to take full advantage of the entry data model, 2 00:00:04,280 --> 00:00:06,200 starting with our Controller. 3 00:00:06,200 --> 00:00:10,230 Instead of specifying a parameter for each request form field that we need to 4 00:00:10,230 --> 00:00:15,920 capture, we can simply use a parameter of type entry named Entry. 5 00:00:15,920 --> 00:00:17,500 How was this possible? 6 00:00:17,500 --> 00:00:22,280 MVCs model binder will recognize that our parameter is an instance of a class or 7 00:00:22,280 --> 00:00:28,420 reference type instead of a value type like string, int, double, bull, or 8 00:00:28,420 --> 00:00:34,250 date time and attempt to bind the incoming form field values to its properties. 9 00:00:34,250 --> 00:00:38,270 As long as the field names match the classes property names 10 00:00:38,270 --> 00:00:42,420 the entry object's properties will contain the expected values. 11 00:00:42,420 --> 00:00:45,800 Before we move on to updating our view, let's update each of our 12 00:00:45,800 --> 00:00:51,208 add action methods to pass an instance of the entry data model to our view. 13 00:00:51,208 --> 00:00:55,780 For the git version of our add method we need to instantiate a new model instance. 14 00:00:56,870 --> 00:01:00,700 Var entry equals new Entry. 15 00:01:01,770 --> 00:01:04,793 I'll go ahead and default the date property to today. 16 00:01:10,741 --> 00:01:13,822 And pass the entry variable to the few method call. 17 00:01:18,461 --> 00:01:20,705 For the post version of the add method, 18 00:01:20,705 --> 00:01:24,380 we just need to pass the entry parameter to the view method call. 19 00:01:27,959 --> 00:01:30,690 Let's turn our attention to our View. 20 00:01:30,690 --> 00:01:33,230 First, we'll make our view strongly typed 21 00:01:33,230 --> 00:01:35,842 by adding a model directive to the top of the View. 22 00:01:35,842 --> 00:01:37,459 @model 23 00:01:37,459 --> 00:01:45,960 Treehouse.FitnessFrog.Models.Entry. 24 00:01:45,960 --> 00:01:47,640 By making our view strongly typed, 25 00:01:47,640 --> 00:01:52,080 the entry model instance that is being passed into the controllers call to 26 00:01:52,080 --> 00:01:56,770 the view method will now be available via the views model property. 27 00:01:56,770 --> 00:01:59,940 We can also update our label, text box and 28 00:01:59,940 --> 00:02:04,940 text area HTML helper methods to their strongly typed versions. 29 00:02:04,940 --> 00:02:08,980 Starting with the date field label, we'll change the label method call 30 00:02:08,980 --> 00:02:13,770 to label four and replace our date string with a => expression. 31 00:02:13,770 --> 00:02:18,390 Remember, you can think of a => expression as an anonymous method. 32 00:02:18,390 --> 00:02:23,700 The m here is a method parameter that is a reference to our views model property. 33 00:02:23,700 --> 00:02:29,250 The => operator is the transition from the parameter list to the method body. 34 00:02:29,250 --> 00:02:32,350 And m.Date is the property on our model 35 00:02:32,350 --> 00:02:35,160 that we're returning from our anonymous method. 36 00:02:35,160 --> 00:02:38,030 This approach gives us a strongly typed way 37 00:02:38,030 --> 00:02:42,310 to specify the model property that we want to render a label for. 38 00:02:42,310 --> 00:02:47,620 Replacing our date string literal with a => expression is a huge improvement. 39 00:02:47,620 --> 00:02:51,390 Instead of having to just magically know what our field name is 40 00:02:51,390 --> 00:02:55,900 Visual Studio is able to show us the list of available properties on our model. 41 00:02:55,900 --> 00:03:01,150 This reduces the amount of typing we have to do and decreases the chance for errors. 42 00:03:01,150 --> 00:03:05,660 We can also update our TextBox method call to it strongly typed version. 43 00:03:05,660 --> 00:03:10,361 TextBoxFor it also takes a => expression as its first parameter and 44 00:03:10,361 --> 00:03:13,123 we no longer need the second parameter, 45 00:03:17,241 --> 00:03:20,364 Let's update our other fields by using the same copy and 46 00:03:20,364 --> 00:03:22,899 paste trick that I did in the previous video. 47 00:03:22,899 --> 00:03:27,684 This time I'll remove the property name and preceding dot before copying and 48 00:03:27,684 --> 00:03:29,531 pasting to the other fields. 49 00:03:42,968 --> 00:03:48,292 Now, we just need to go back and press dot at the end of the in variables to display 50 00:03:48,292 --> 00:03:53,500 the list of available properties and select the one that we're looking for. 51 00:03:53,500 --> 00:03:59,704 .ActivityId, and again .ActivityId. 52 00:04:02,916 --> 00:04:08,437 .Duration and .Duration, 53 00:04:11,444 --> 00:04:17,298 .Intensity and .Intensity, 54 00:04:18,733 --> 00:04:24,347 And lastly, .Exclude and 55 00:04:24,347 --> 00:04:27,040 .Exclude. 56 00:04:27,040 --> 00:04:29,130 And now the notes field. 57 00:04:29,130 --> 00:04:32,019 Change label to labelFor, and 58 00:04:32,019 --> 00:04:37,028 provide a => expression to the m.Notes property. 59 00:04:44,582 --> 00:04:49,216 And text area to TextAreaFor provide a => 60 00:04:49,216 --> 00:04:54,115 expression again to the m.Notes property. 61 00:05:01,267 --> 00:05:03,370 And remove the second parameter. 62 00:05:05,886 --> 00:05:09,639 After the break, we'll make one more change to our controller and 63 00:05:09,639 --> 00:05:10,720 test our changes.