Skip to content

ASPNET Core 5 MVC Bootstrap Responsive Web Programming Lecture 7 Model Binding Entity FMWK

FurkanGozukara edited this page Nov 16, 2026 · 1 revision

ASP.NET Core 5 - MVC - Bootstrap - Responsive Web Programming, Lecture 7: Model Binding, Entity FMWK

ASP.NET Core 5 - MVC - Bootstrap - Responsive Web Programming, Lecture 7: Model Binding, Entity FMWK

image Hits Patreon BuyMeACoffee Furkan Gözükara Medium Codio Furkan Gözükara Medium

YouTube Channel Furkan Gözükara LinkedIn Udemy Twitter Follow Furkan Gözükara

#SoftwareDevelopment #Software #Engineering #CSharp #Coding #Course

Asp.NET Core V5 - MVC Pattern - Bootstrap V5 - Responsive Web #Programming with C# Full Course Playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffsnAWtgk4ja3HN3xgMKF7BOE

GitHub repository of the course : https://github.com/FurkanGozukara/Responsive-Web-Design-With-ASP.NET-5-and-MVC-Pattern-and-BootStrap-5-2021

Discord channel link of the course : https://discord.gg/6Mrb8MwteQ

How to use Discord : https://youtu.be/AEwPtYiLvsQ

In Lecture 7:

  • What are Models in ASP.NET MVC

  • How to use Entity framework in ASP.NET MVC Core to do database operations

  • How to do old-school style form / action postback with ASP.NET MVC Core

  • How to update / insert database with form action postback by using Entity Framework

  • What is model binding in ASP.NET MVC

  • How to use model binding to do client - server communication with postback

  • How to properly use attribute routing to do server side postbacks as wanted

  • Simple database generation to do model / postback / update / select database examples

  • MS-SQL server profiler to analyze Entity Framework queries

  • How to use route order to handle order of conflicting attribute routing

last page : https://asp.mvc-tutorial.com/layout/introduction/

Please subscribe and make comments.

This course requires fundamental knowledge about programming and C#. So please watch our below playlists related to C#.

Our courses playlists are like below:

[1] Introduction to Programming Full Course with C# playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffskoSXySh0MdiayPJsBZ7m2o

[2] Advanced #Programming with C# Full Course Playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffslHaBdS3RUW26RKzSjkl8m4

[3] Object Oriented Programming Full Course with C# playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffsnH3XJb66FDIHh1yHwWC26I

[4] Asp.NET Core V5 - MVC Pattern - Bootstrap V5 - Responsive Web #Programming with C# Full Course Playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffsnAWtgk4ja3HN3xgMKF7BOE

[5] Artificial Intelligence (AI) and Machine Learning (ML) Full Course with C# Examples playlist: https://www.youtube.com/playlist?list=PL_pbwdIyffskVschrADCL6KEnL_nqDtgD

[6] Software Engineering Full Course playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffslgxMVyXhnHiSn_EWTvx1G-

[7] Security of Information Systems Full Course playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffslM_o92NwkaUzD7C6Fekx26

[8] (Turkish) Bilgisayar Becerileri Tam Ders playlist : https://www.youtube.com/playlist?list=PL_pbwdIyffsmyE2e909ea1MXLcMb8MenG

auto subtitle timing : NA

Video Transcription

  • 00:00:02 Hello dear students, welcome to the lecture 7 of responsive web design with asp.net 5

  • 00:00:08 and we see pattern and bootstrap.

  • 00:00:11 So as you are seeing I have prepared your project details.

  • 00:00:16 I will post it to the GitHub and I will talk about about it at the end of the lecture.

  • 00:00:22 So if you remember we have seen routing constraints at the last lecture lecture slide 6, so we

  • 00:00:31 will

  • 00:00:32 continue with

  • 00:00:34 let's say models.

  • 00:00:39 Okay.

  • 00:00:41 We already have an have a have an idea about model, but we will see about more details

  • 00:00:50 of models in this lecture.

  • 00:00:54 So I will continue from our previous code and let me copy and paste it.

  • 00:01:01 Alright, let's open the project.

  • 00:01:09 If you're remembering it at the previous lectures lecture 6, we have composed a new project

  • 00:01:20 from scratch and no need to do it every time so we can continue from our previous lecture

  • 00:01:29 and I am generating a separate folder for your easiness to see each weeks called individually.

  • 00:01:38 It is also possible to do that with GitHub course.

  • 00:01:43 Repository management, but it may be hard for you.

  • 00:01:48 So I'm just in copy and paste.

  • 00:01:56 Okay, let's rename.

  • 00:01:59 Okay, this is not renaming everything but it is at least better than nothing.

  • 00:02:06 Okay.

  • 00:02:07 So let's start with models.

  • 00:02:13 introduction

  • 00:02:15 In the previous chapters, we have gone more in depth with both the see controller and

  • 00:02:20 the view of the MVC pattern.

  • 00:02:22 So in this chapter, we'll focus on the M model we're talking about it last because you can

  • 00:02:28 actually have a website based on the MVC pattern without using a model.

  • 00:02:32 Although that would be a pretty simple website.

  • 00:02:34 It's just sort of we don't need models to print something on the screen.

  • 00:02:39 We have already seen that we can just use return.

  • 00:02:43 And content from our controllers such as here.

  • 00:02:52 You see, this is just returning a content to the screen.

  • 00:02:56 It is not using any model or we can Define and Implement whatever we need on our razor

  • 00:03:03 Pages CSS HTML Pages.

  • 00:03:06 They also don't need model.

  • 00:03:08 For example.

  • 00:03:09 This page doesn't need a model to be working.

  • 00:03:12 However,

  • 00:03:14 That is against the strategy of MBC.

  • 00:03:23 Okay.

  • 00:03:24 And therefore we are going to see models in more details right now website.

  • 00:03:34 What is a model?

  • 00:03:36 As we discussed in the quick start part of this tutorial where we quickly added.

  • 00:03:41 Or it could be a complex object at as we discussed in the quick start part of this tutorial where

  • 00:03:48 we quickly added a controller a view and a model to our project the model in an MVC application

  • 00:03:53 should represent the current state of the application as well as business logic and

  • 00:03:58 or operations.

  • 00:03:59 Okay.

  • 00:04:00 So model in MVC application should represent the current state of the application as well

  • 00:04:06 as the business logic and or operations, okay?

  • 00:04:10 Operations a model can be any kind of object found in the framework.

  • 00:04:15 It could in fact be a simple number or string or it could be a complex object instantiated

  • 00:04:20 from a class eg a user class which holds information about a user a guest book entry item which

  • 00:04:26 contains a post to a guest book or anything else that also means that your model can be

  • 00:04:31 a class you already have EG something that comes from the database or a class that you

  • 00:04:36 create specifically to become a model for one or several views.

  • 00:04:40 A very important aspect of the MVC pattern is the separation of concerns SOC is achieved

  • 00:04:47 by encapsulating information inside a section of code, making each section modular and then

  • 00:04:52 having strict control over how each module communicates.

  • 00:04:56 So you see separation of concerns is really important.

  • 00:05:01 It allows you to have individual and different teams working on eh concern is SLS.

  • 00:05:09 s OC is separation of concerns and this is what is fundamentally and we see is

  • 00:05:19 Communicates for the MVC pattern this means that both the view and the controller can

  • 00:05:24 depend on the model but the model doesn't depend on neither The View nor the controller

  • 00:05:29 this turns your models into a module that can exist even outside of the MVC framework

  • 00:05:34 EG for use in a desktop application.

  • 00:05:37 And then it has the added benefit of allowing your models to be tested without the visual

  • 00:05:41 representation EG through the use of unit tests.

  • 00:05:44 Okay.

  • 00:05:45 This is the really important so you see with this.

  • 00:05:48 approach we will challenge use our model in any other kind of application for example,

  • 00:05:54 a desktop application and mobile application server application, whatever you need because

  • 00:06:02 it is separate from the wheel or the controller and this also allows us to do unit tests without

  • 00:06:13 any visual representation because it is independent of the visual representation the

  • 00:06:18 We the visual representation is the may depend on the model but model does not have to depend

  • 00:06:26 on anything.

  • 00:06:31 Okay?

  • 00:06:36 As mentioned the model can be a class already defined in your project or it can be a new

  • 00:06:40 class you had specifically to act as a model therefore models in the asp.net MVC framework

  • 00:06:47 usually exists in a folder called models or they come from outside of the project EG from

  • 00:06:53 a class Library a model doesn't have to inherit from a specific base class or anything like

  • 00:06:59 that.

  • 00:07:00 They are truly just regular dotnet classes.

  • 00:07:03 There are a couple of ways to enrich your model classes with MVC related information

  • 00:07:07 though, but we'll discuss that later.

  • 00:07:10 summary

  • 00:07:12 the model in an MVC application should represent the current state of the application as well

  • 00:07:17 as business logic and or operations in the upcoming articles of this chapter will dig

  • 00:07:23 deeper into the more advanced model related subjects.

  • 00:07:26 Okay, let's continue.

  • 00:07:29 Okay, so I'll be models.

  • 00:07:33 view models

  • 00:07:35 We have already worked with models multiple times in this tutorial.

  • 00:07:39 But if you look around and other material about asp.net MVC or just the MVC pattern

  • 00:07:44 in general, you may notice that something called a view model is often mentioned, but

  • 00:07:49 what's the difference between a model and a view model actually whenever you pass a

  • 00:07:54 model to a view it's considered a view model because it's used by the view.

  • 00:07:59 In other words.

  • 00:08:00 There doesn't have to be a difference.

  • 00:08:01 You can use your models as view models interchangeably.

  • 00:08:05 There are however a lot of situations where you may want to create a specific view model

  • 00:08:09 for a specific view.

  • 00:08:12 This can be to extend our simplify an existing model or because you want to represent something

  • 00:08:16 in a view that's not already covered by one of your models.

  • 00:08:20 View models are often placed in their own directory in your project called view models.

  • 00:08:25 Again.

  • 00:08:26 This is just a convention and since view models are just regular dotnet classes.

  • 00:08:31 You are free to place them wherever you want to but it often makes sense to follow these

  • 00:08:35 conventions.

  • 00:08:36 Some people also prefer to post fix the name of the class with the word view model EG address

  • 00:08:41 view model or edit user view model.

  • 00:08:44 So to use it so we can put our view models in a folder called a

  • 00:08:50 Me Mother's and we can name them as ending with a view model such as edit user give model.

  • 00:08:58 However be models are also regular dotnet classes.

  • 00:09:02 Okay, let's continue.

  • 00:09:08 when to use a view model

  • 00:09:10 here are a couple of situations where you could benefit from a new model to represent

  • 00:09:16 something in a view that's not already contained by an existing model.

  • 00:09:19 When you pass a model to a view you are free to pass eg a string or another simple type.

  • 00:09:25 But if you want to pass multiple values, it might make more sense to create a simple view

  • 00:09:29 model to hold the data like this one.

  • 00:09:32 Okay, so address we model it has two properties.

  • 00:09:37 We can so what is the difference between this let's continue to access the data of multiple

  • 00:09:44 models from the same view.

  • 00:09:46 This is relevant in a lot of situations EG when you want to create a form where you can

  • 00:09:51 edit the data of multiple models at the same time.

  • 00:09:54 You could then create a view model like this.

  • 00:09:57 Okay.

  • 00:09:58 So you see there is a fundamental difference.

  • 00:10:02 Normally we are able to pass only single model to our view.

  • 00:10:09 But what if you want to pass multiple models to our view then you see there is a parent

  • 00:10:16 view model which includes objects of different models.

  • 00:10:20 For example like this.

  • 00:10:21 You see more than one type more than one model due to type, okay.

  • 00:10:29 To simplify an existing model imagine that you have a huge class with information about

  • 00:10:34 a user perhaps even sensitive information like passwords when you want to expose this

  • 00:10:40 information to a view it can be beneficiary to only expose the parts of it.

  • 00:10:45 You actually need for instance.

  • 00:10:47 You may have a small widget showing that the user is logged in which username they have

  • 00:10:52 and for how long they have been logged in.

  • 00:10:54 So instead of passing your entire user model you can pass in a much leaner view model.

  • 00:10:59 Designed specifically for this purpose.

  • 00:11:04 So this is just a view model.

  • 00:11:06 Let's continue.

  • 00:11:08 To extend an existing model with data only relevant to the view on the other hand.

  • 00:11:13 Sometimes your model contains less information than what you need in your view an example

  • 00:11:18 of this could be that you want some convenience Properties or methods which are only relevant

  • 00:11:22 to the view and not your model in general like in this example where we extend a user

  • 00:11:27 model called Web user with a login duration property calculated from the last login date

  • 00:11:32 time property already found on the web user class.

  • 00:11:36 Okay.

  • 00:11:39 From there on there are two ways of doing things.

  • 00:11:41 You can either extend this class inherit from it or at a property for the web user instance

  • 00:11:46 on The View model.

  • 00:11:48 Okay, so probably class user info view model.

  • 00:11:52 It includes web users and then an additional parameter like this.

  • 00:11:58 Okay, and there is also extended version by taste.

  • 00:12:02 Both works.

  • 00:12:04 Okay, there is nothing new in this.

  • 00:12:10 Part of the tutorial it is same as before whatever we have seen so far.

  • 00:12:19 Okay, let's continue.

  • 00:12:21 Okay, then model binding.

  • 00:12:28 model binding

  • 00:12:31 communication between a client usually a browser and the web server is very simple strings

  • 00:12:35 are passed back and forth because the client doesn't have any understanding of your fancy

  • 00:12:40 dot but can before moving to that.

  • 00:12:42 I want to check something.

  • 00:12:45 So let's open Google.

  • 00:12:47 B model versus mode of in is without net and we see let's see if there are any differences.

  • 00:13:01 Because because it already looks like exactly same.

  • 00:13:25 Okay, that's looks like no difference what Nestle design sir.

  • 00:13:54 serves as a data binder between

  • 00:13:55 - well it started from Dash.

  • 00:14:01 In the simplest of terms.

  • 00:14:02 I like to think of the following.

  • 00:14:05 Model strictly looks and feels like your data model for all intents and purposes.

  • 00:14:10 It is only a class representation of your data model.

  • 00:14:14 It has no knowledge of your view or any elements within your view that said it should not contain

  • 00:14:19 any attribute decorators IE required length Etc that you would use for your view.

  • 00:14:27 View model serves as a data binder between your view and your model and in many cases

  • 00:14:32 is also a rapper for your model.

  • 00:14:35 It would be rendered useless without the view.

  • 00:14:37 So it typically isn't reusable across multiple views and controllers like a standard model

  • 00:14:42 is

  • 00:14:44 As an example your model may have the following properties which are direct representations

  • 00:14:48 of your data source.

  • 00:14:51 Public string first name get set public string last name get set.

  • 00:14:57 Now since your view model is tied to your view.

  • 00:15:00 It may have the following property which concatenates the models first name field and last name

  • 00:15:04 field together as one string.

  • 00:15:07 Display name equals customer name public string customer full name get return string format

  • 00:15:13 0 1 my model DOT.

  • 00:15:16 First name my model dot last name.

  • 00:15:18 Okay.

  • 00:15:19 So you see view model simply users the model itself and formats.

  • 00:15:27 It's in a special way that particular view will use.

  • 00:15:31 Okay.

  • 00:15:32 That's all what's it about there is nothing fancy.

  • 00:15:37 Avoid it.

  • 00:15:38 Okay, so it is just a used approach.

  • 00:15:41 Okay, let's continue with our model binding from beginning.

  • 00:15:51 model binding

  • 00:15:53 communication between a client usually a browser and the web server is very simple strings

  • 00:15:58 are passed back and forth because the client doesn't have any understanding of your fancy

  • 00:16:03 dotnet objects.

  • 00:16:04 So back in the old days of ASP classic in asp.net web forms before the MVC framework

  • 00:16:11 was introduced into the dotnet framework the process of updating a model was a bit cumbersome.

  • 00:16:17 First you would have to create a form with all the fields that the user could change

  • 00:16:22 when this form was posted back to the server.

  • 00:16:24 You would have to read each of the form fields and assign it to your model if we were to

  • 00:16:29 take this approach and use it with asp.net MVC.

  • 00:16:33 It would look something like this.

  • 00:16:35 Okay.

  • 00:16:36 So let's start making this as an example, so we will understand better.

  • 00:16:42 Okay.

  • 00:16:43 So first I am going to add a new page and let's add a folder as lecture 7 and inside

  • 00:16:53 the sector 7 I'm going to add index page index view physically.

  • 00:17:00 Okay in Vegas.

  • 00:17:07 We can give any name to this.

  • 00:17:10 Okay, and then I'm going to add lecture 7 controller.

  • 00:17:16 It's controller.

  • 00:17:20 And it will be simply lecture 7 controllers.

  • 00:17:28 Okay.

  • 00:17:30 So in our view let's print lecture seven you and let's set our startup default page to

  • 00:17:44 lecture 7 and these were some custom routes if you remember and I'm going to change the

  • 00:17:56 Alt

  • 00:17:58 Roots how we were doing it?

  • 00:18:05 Okay, let's I think you will doing it.

  • 00:18:14 from here, okay and points

  • 00:18:21 custom costume

  • 00:18:22 Yeah, maybe here if I add it here.

  • 00:18:29 Default apps by default.

  • 00:18:31 It will look for lecture seven.

  • 00:18:35 nothing new controlling relationship

  • 00:18:39 seven

  • 00:18:40 okay action will be index.

  • 00:18:45 Yes.

  • 00:18:46 and it's winter clothes my put

  • 00:18:57 But this was cascading we don't need that.

  • 00:19:05 I won't repeat this as a default.

  • 00:19:11 But let's try.

  • 00:19:17 If this doesn't work, I will just check to Google because I can't remember it exactly.

  • 00:19:36 So this will go to the lecture seven controller with action in days, which means it will call

  • 00:19:41 index CH HTML.

  • 00:19:43 Okay, it is starting.

  • 00:19:52 In my let's look for other methods.

  • 00:20:06 Okay, it is not working yet.

  • 00:20:12 So.

  • 00:20:13 However, it would work like this.

  • 00:20:16 Let me show you see it is working.

  • 00:20:19 I can also use index like this port is working.

  • 00:20:24 However, the default is not working.

  • 00:20:26 So yeah, I have to default here.

  • 00:20:32 So, let's see movies.

  • 00:20:36 We don't need it.

  • 00:20:37 And here's let's control the route default controllers.

  • 00:20:42 Okay lecture seven action index and we don't need ID yet.

  • 00:20:50 You don't need.

  • 00:20:55 Okay, let's run it.

  • 00:21:02 It should work by default right now.

  • 00:21:15 Okay lecture 7 is now our default route and we can continue so you see we are going to

  • 00:21:22 generate a post and it will post some values to our model model that first name last name

  • 00:21:36 and name.

  • 00:21:39 These are the default values by the way, so let's do it.

  • 00:21:42 So this is a simple

  • 00:21:46 Model which includes first name and last name?

  • 00:21:50 Okay.

  • 00:21:51 So let's add our models as lecture 7.

  • 00:21:56 If I will just add a simple class and I will call it as lectures 7.

  • 00:22:05 Okay.

  • 00:22:06 And here I am going to have two parameters string.

  • 00:22:11 It will be S our first name.

  • 00:22:18 It's prob.

  • 00:22:21 Stink is our last name and where am I going to use this model?

  • 00:22:29 I'm going to use it in my index as okay ads.

  • 00:22:38 model equal to

  • 00:22:40 here's okay equal to if I remember, correct.

  • 00:22:50 Well not equal to bi just typing like this make sure six models thoughts later said,

  • 00:22:58 okay, so this is setting the model and now I can copy and paste this.

  • 00:23:05 So it is riding up for let's write it ourselves.

  • 00:23:09 So form, you see it's a code snippet when I type double tap tab, it will generate it

  • 00:23:15 like this.

  • 00:23:16 So the action will be posting two hours.

  • 00:23:20 Controller which is lecture seven index.

  • 00:23:24 Okay.

  • 00:23:25 So this is a posting URL and then we will set the method as we can set it as post or

  • 00:23:37 get you are going to set it as post and now we are going to set some parameters to post

  • 00:23:43 so they will be input.

  • 00:23:46 Okay type will be 'text since they will be text.

  • 00:23:50 They will be visible.

  • 00:23:51 And we are going to set a name.

  • 00:23:54 So the name will be txt.

  • 00:23:56 First name and the value.

  • 00:23:59 So the value will come from our model when the page is loaded.

  • 00:24:05 So I will set it as model dots.

  • 00:24:10 Okay, first name by default.

  • 00:24:15 Okay, and then I'm going to set another input.

  • 00:24:20 Okay type will be 'text name will be.

  • 00:24:27 It's the last name and the value.

  • 00:24:30 So this value will come from our model.

  • 00:24:33 Modal by the it is a big m dot last name.

  • 00:24:38 Okay, this is not needed and finally we will have form submit.

  • 00:24:45 So it will be type submit' input.

  • 00:24:48 I've submit and then you're going to have value of splink update model.

  • 00:25:00 Okay?

  • 00:25:01 All right, and it is ready.

  • 00:25:06 So and let's also make get into our controller.

  • 00:25:13 So this is index action and it is just returning will let's define a model and to get to use

  • 00:25:22 it.

  • 00:25:23 I'm going to add using.

  • 00:25:26 Models, so it will be available and here I will Define a lecture 7 model.

  • 00:25:34 equals new mother of lecture seven bite me you see we should change this name of this

  • 00:25:42 like

  • 00:25:43 because it can stay it's it is not a problem.

  • 00:25:52 So when I am setting it, I will also set the default value is as first name equal to default

  • 00:25:59 first name and the last name will be equal to

  • 00:26:02 Okay default last name.

  • 00:26:07 So this will get loaded into the video.

  • 00:26:11 When it is first getting lat let's run and see how it is looking.

  • 00:26:22 Assume that you are loading some data from database and then you are allowing users to

  • 00:26:32 update that data.

  • 00:26:34 Go to the disease index action, but it doesn't get any parameters.

  • 00:26:39 Then I will going to add a post action as well for updating.

  • 00:26:46 You see default first name and default last name and updates model here.

  • 00:26:52 So let's add an update model team, by the way.

  • 00:27:00 I think we can do something else and

  • 00:27:03 But we have a static values that we can use as a database.

  • 00:27:11 Yeah, we have published DirecTV and let's assume that you have here some public static

  • 00:27:23 first string.

  • 00:27:26 Or maybe we can start using database in Rio de yeah.

  • 00:27:36 Yeah, let's do it.

  • 00:27:38 So I will use Entity Framework.

  • 00:27:43 In these lectures for as a methodology of obtaining and doing database operations.

  • 00:27:54 If you don't know how Entity framework works.

  • 00:27:57 I am teaching that in the advanced programming.

  • 00:28:00 You can watch Advanced programming lecture 5 6 7 and you will understand it.

  • 00:28:07 Okay, let's open the SQL Server management Studio.

  • 00:28:18 So if you don't know how Entity framework works, let me show you which.

  • 00:28:26 lessons on them

  • 00:28:27 This is our Channel.

  • 00:28:33 Andy go to Advanced programming

  • 00:28:40 And here's another students.

  • 00:28:41 Welcome to the lecture 1 of introduction to programming.

  • 00:28:45 Okay, I think it is.

  • 00:28:47 Yes lecture 5 LEDs.

  • 00:28:49 I start teaching the indiscriminate lecture 6

  • 00:28:55 Continue with aunt's funeral and with lecture seven after watching these three videos, you

  • 00:29:03 will have full knowledge and understanding of Entity framework.

  • 00:29:08 Okay?

  • 00:29:09 Well, which dotnet course it is hard to use and Sven were to be able to use it.

  • 00:29:16 We have installed if he Core Power Tools you can install it from I think maybe in yeah

  • 00:29:25 it is it is an

  • 00:29:28 tension or stool

  • 00:29:31 It was external to maybe I don't know you can just look for it.

  • 00:29:35 Like if you course power tools and then you will just do more than install it.

  • 00:29:43 Okay, it is inside Market Visual Studio Marketplace.

  • 00:29:47 Just all modern is selected seat and

  • 00:29:50 okay, let's compose a new database.

  • 00:29:55 A very simple one, so I will call this database as MVC.

  • 00:30:05 Let's compose a table inside our database as table column name first colander.

  • 00:30:15 First name.

  • 00:30:18 Let's add a user ID as well.

  • 00:30:20 Okay, so it's for the integers I want I'll make a primary key but not Auto increment

  • 00:30:29 first name.

  • 00:30:32 Let's make it Embark character 50 and last name, okay.

  • 00:30:37 Let's also make it unlock.

  • 00:30:42 I've got 50.

  • 00:30:44 Let's save it as Tyrael users.

  • 00:30:48 Okay?

  • 00:30:49 Okay, we have our table when we refresh you will see now.

  • 00:30:54 We are going to add this into our project which reverse engineer from iffy Core Power

  • 00:31:02 Tools.

  • 00:31:03 Okay.

  • 00:31:04 Now this is working.

  • 00:31:09 You.

  • 00:31:10 See I'm going to pick okay.

  • 00:31:13 I have to change the data database name.

  • 00:31:16 So let me restart reverse Engineers.

  • 00:31:21 Okay, so from here, I am going to add another connection here.

  • 00:31:28 Yes, delete it and server name.

  • 00:31:33 That's get the server name with new query.

  • 00:31:36 Select a server name.

  • 00:31:38 Okay.

  • 00:31:39 So this is my server name when I paste it.

  • 00:31:46 The database names comes it is a me see okay.

  • 00:31:51 You see now MVC is selected.

  • 00:31:53 You see desktop you ulh for and 626 is my server name and MVC is my database name.

  • 00:32:02 Now it's fetching tables.

  • 00:32:05 It says on single table or J and include connections think in generated code and nothing else we

  • 00:32:13 need.

  • 00:32:15 Okay.

  • 00:32:16 Now it will add related code to the my project you see it is edit as MVC context.

  • 00:32:29 It also includes database connection string and my users table.

  • 00:32:34 Okay.

  • 00:32:36 So what am I going to do is simply I will fetch the model.

  • 00:32:44 From database as okay using OK and we see context my contacts equal to new MVC context.

  • 00:32:59 Okay, and I will get ID in the user ID by default one, okay.

  • 00:33:16 one

  • 00:33:18 Let's postpone composer model here and we are going to do simply create a query and

  • 00:33:31 this value my wash your user you will be equal to my context that we are users start.

  • 00:33:42 Okay, I think I will use select.

  • 00:33:45 We are equal to PR dots user ID equal to user ID so we can also make it should pork.

  • 00:34:00 This is equally cool.

  • 00:34:03 And if this is not know if we are users.

  • 00:34:09 Not equal null.

  • 00:34:11 So it is found but you are going to do is we will set my model does first name equal

  • 00:34:18 to VR users that first name.

  • 00:34:22 Okay, interesting boy.

  • 00:34:26 It's not here.

  • 00:34:32 Is it returning users type?

  • 00:34:47 Then I will use first or default like this it will change now.

  • 00:34:58 Let me not select but where is more proper?

  • 00:35:12 Yeah, select environments difference now.

  • 00:35:15 Okay.

  • 00:35:16 Now it is here.

  • 00:35:18 First name, it's my model that last name will be equal to BR user dot plus day and now I

  • 00:35:27 am going to write update but let's run our application and see what we are seeing on

  • 00:35:36 screen.

  • 00:35:38 You should always develop your application step by step.

  • 00:35:42 And I'm sure that or be sure that it is working before you are progressing to Next Step.

  • 00:35:51 This will help you tremendously.

  • 00:35:56 Okay.

  • 00:36:00 We should see as same as the last time because we didn't do anything new on the on the visual

  • 00:36:16 side.

  • 00:36:17 Yeah.

  • 00:36:18 Now we are going to write our update action.

  • 00:36:22 So the update action will simply

  • 00:36:25 update okay, so I am going to

  • 00:36:35 get this into a private comment.

  • 00:36:38 as I with Boyd's

  • 00:36:42 Update models or refresh model.

  • 00:36:46 They're fresh.

  • 00:36:48 Model, okay, and this will simply take model.

  • 00:36:53 Okay as my model and we will call it here since this is a class.

  • 00:37:03 It is reference type therefore once this is updated here.

  • 00:37:08 It will be also updated here and I also need to provide user ID.

  • 00:37:13 Integers users ID.

  • 00:37:15 I can't give make this something like this.

  • 00:37:21 Okay here I will provide user ID.

  • 00:37:26 Okay.

  • 00:37:27 Why do you think I have made it like this because after the database update I will call

  • 00:37:32 this refresh model.

  • 00:37:36 And here I will make update users.

  • 00:37:41 And simply it will update the database how first it will get the VR user if it is not

  • 00:37:52 existing if it is null.

  • 00:37:56 We are going to compose a new instance of T values of starts.

  • 00:38:07 But user is equal to Nu TBL users.

  • 00:38:13 And here we will set the values as first name will be okay.

  • 00:38:18 Now, let's get our code from here.

  • 00:38:22 So we will be getting request form.

  • 00:38:26 Okay.

  • 00:38:27 So in the request form since this is a post action results.

  • 00:38:33 We are going to use the same name of our remove close this

  • 00:38:40 Index.html of lecture seven you see these are getting confused.

  • 00:38:47 Therefore.

  • 00:38:48 I am going to change this index as

  • 00:38:54 Lectures lecture 7 index I can give any custom name I want so it will be better readable.

  • 00:39:02 And since I have made this change, I'm going to change this as to not hear hear.

  • 00:39:11 I'm going to return Viv with the name of the view as like this.

  • 00:39:18 And then okay, so in lecture 7 index.html.

  • 00:39:24 This is the TX name of the post parameters.

  • 00:39:28 Okay, let's get this into controllers.

  • 00:39:35 Yeah, and this will be the first name and this will be the last name.

  • 00:39:44 Also, we will get user ID from here.

  • 00:39:51 So it will be the user ID will be equal to

  • 00:39:54 this one

  • 00:39:57 and then we will add this into the context.

  • 00:40:05 my users

  • 00:40:06 Okay, and then actually we met probably we don't even need this.

  • 00:40:16 Okay, because it will just update it after the edit context and

  • 00:40:22 Save changes.

  • 00:40:25 I am not sure this I am not sure if this will work for updates.

  • 00:40:28 This will work for the first time for sure, but for other things we will see and we will

  • 00:40:35 not return anything, but we will just call this I action result basically will call.

  • 00:40:47 index by these bones

  • 00:40:51 I action results public Voyage.

  • 00:40:53 This can be just a public toilet.

  • 00:40:56 Yeah update use and we will call index.

  • 00:41:02 Wait use right and nothing else.

  • 00:41:09 Okay, and yeah, and we will post to this.

  • 00:41:17 Yes as a method of the accusers.

  • 00:41:21 So this will go to the action as lecture 7 controller and update user method as post.

  • 00:41:29 Yeah now we should work.

  • 00:41:32 Let's also add some.

  • 00:41:34 Break point to see how it is working.

  • 00:41:48 At the first time I'm sure it's closed path for updates.

  • 00:41:51 This may not work there for sure.

  • 00:41:56 I will test it.

  • 00:42:03 Okay, so let's set our name as music color update model.

  • 00:42:11 Let's also check our database tables.

  • 00:42:13 Okay, there's nothing here.

  • 00:42:16 We can also see the executed queries with tools.

  • 00:42:22 Let me let me show you again to SQL server profilers and here's I will say speak tunic

  • 00:42:35 as what's needs to be logos in.

  • 00:42:37 Here tuning in and we will see the our query as well.

  • 00:42:44 So let's step by step.

  • 00:42:46 So it is composed an instance of TBR users.

  • 00:42:49 It has added it to context save changes and now it will return in day so I am getting

  • 00:42:56 here it will get into refresh model.

  • 00:42:59 So it will pitch to users and user is here because we can see it in the database as well

  • 00:43:05 and then which will set the

  • 00:43:07 matters, and then it will be returned to model and

  • 00:43:15 Oh.

  • 00:43:18 testing

  • 00:43:22 so we have returned its view but this page is not refresh its why?

  • 00:43:29 Because the URL has changed into update user.

  • 00:43:37 What is about people using a post methods interesting let's refresh.

  • 00:43:47 And let's see what happens.

  • 00:43:52 spontaneous

  • 00:43:53 Oh now it says this order exists probably.

  • 00:43:58 Yeah, first we need to check if it is existing or not.

  • 00:44:07 So you have to make a check.

  • 00:44:11 What kind of check if you wander?

  • 00:44:15 we have some code here that it's

  • 00:44:18 let's make the check like this.

  • 00:44:23 Maria usually equal to my context.

  • 00:44:28 party girl users rash

  • 00:44:32 Why do I this PR you can name this as anything?

  • 00:44:39 This is short of parameters.

  • 00:44:41 Usually use it as user ID if we are users.

  • 00:44:47 Does not equal null.

  • 00:44:50 we are going to

  • 00:44:55 make changes like this use of dots first.

  • 00:45:09 Okay, also first or default unless it first.

  • 00:45:18 Not default.

  • 00:45:19 Okay, first name equal to my user got first name.

  • 00:45:26 Last name equal to 90 is it up last time?

  • 00:45:33 Okay, and

  • 00:45:34 Else it will be my contacts at users like this and change now it should work.

  • 00:45:44 However, this post action change it out.

  • 00:45:49 You are all here because it is not easy in cronies and

  • 00:45:54 let's run the application to see how we can make a redirect of

  • 00:46:02 Not change of the barrel.

  • 00:46:14 Let's save our Congress and now we should update the database of to the make a post.

  • 00:46:24 You can also see it in the okay.

  • 00:46:26 You see now select user command executed values have come as Foucault music color and test

  • 00:46:33 I will make it a sketchy color.

  • 00:46:36 It is updated.

  • 00:46:37 And yes, you see test critical.

  • 00:46:40 However, it didn't return back to our playlist URL.

  • 00:46:46 So let's check it out.

  • 00:46:56 Which also post action don't change your let's see if this is possible.

  • 00:47:07 You don't Ajax.

  • 00:47:13 Interesting return you indexing how to what we are already doing that.

  • 00:47:34 We are already returning in VF.

  • 00:47:50 Here's

  • 00:47:53 Okay, we need to redirect action probably.

  • 00:48:20 Oh.

  • 00:48:33 Spell yeah, I think I know the reason let's try it.

  • 00:49:04 So we will make this as I action result.

  • 00:49:10 I need to just simply return wave.

  • 00:49:18 Like this and see what happens.

  • 00:49:23 So this is action results makes a change, I think.

  • 00:49:34 Okay, update user if this doesn't work.

  • 00:49:42 I will try return redirect.

  • 00:49:48 Okay, let's make this first version 2

  • 00:49:55 Okay.

  • 00:49:57 Now we have no model.

  • 00:49:58 Therefore.

  • 00:49:59 We are getting an error.

  • 00:50:02 I see.

  • 00:50:04 because simply it will it has returned it to

  • 00:50:08 behave, but without index action, so I also have to

  • 00:50:17 Define action.

  • 00:50:19 Yeah.

  • 00:50:21 so

  • 00:50:23 I can return live but I also need to action.

  • 00:50:41 So it says new about h.

  • 00:50:52 option

  • 00:50:53 Some action.

  • 00:50:57 Yes.

  • 00:50:59 Okay, so we need to be direct action which only director action and it's fully index

  • 00:51:07 action.

  • 00:51:08 Okay, simply like this space, right?

  • 00:51:12 so after the post it will update and

  • 00:51:16 redirect to action

  • 00:51:19 Okay, let's make this Astros.

  • 00:51:36 University update yes, update it and return it back.

  • 00:51:48 Okay, it is working.

  • 00:51:49 Great.

  • 00:51:50 We can see the update query on here.

  • 00:51:52 Let's see.

  • 00:51:53 Yeah here this is the update query executed by our Entity framework.

  • 00:52:02 And then we refresh the database you can see we can also use this as a adding new users.

  • 00:52:09 How can we do that?

  • 00:52:10 We can do it simply with

  • 00:52:11 Adding a user ID.

  • 00:52:14 Here's it will be txt users ID.

  • 00:52:22 And we won't bind it to anything.

  • 00:52:25 It will be like this and then in the code behind in our action here.

  • 00:52:38 We can just simply like this.

  • 00:52:41 Okay here too.

  • 00:52:50 tryparse

  • 00:52:53 Okay request form.

  • 00:52:56 txt uses

  • 00:52:59 Heidi and out will be equal to user ID.

  • 00:53:08 By the V also we need to first test.

  • 00:53:12 all these to be

  • 00:53:26 Hustle

  • 00:53:32 If this is successful, we will change user ID of users.

  • 00:53:41 Yeah, and we equal to

  • 00:53:46 Is it again?

  • 00:53:59 You see they are getting pretty confusing Darfur.

  • 00:54:03 It would be better to change this to something else.

  • 00:54:09 But yeah now it's working fine.

  • 00:54:13 Maybe we can make this lower case whatever we want.

  • 00:54:18 And now of course we would be needed to change them like this, but you know should board

  • 00:54:28 now we can update insert users sniff users as well.

  • 00:54:32 If you don't provide user ID, it will use the user ID default by one but now

  • 00:54:38 Should work now be provided so we can add new users as well.

  • 00:54:45 However, it will always display the first users because we are using the first years,

  • 00:54:52 but we can also change that.

  • 00:54:54 Yes, we can also change that.

  • 00:54:56 I will show you.

  • 00:54:57 Okay, let's add a new views as user ID to work on gives you color.

  • 00:55:05 Let's edit.

  • 00:55:06 Okay, seasick use contains.

  • 00:55:09 No.

  • 00:55:10 Oh, I see we have to set this as first or default when you use first it is expecting

  • 00:55:19 a real value.

  • 00:55:20 Therefore you have to use first of default.

  • 00:55:23 It makes a difference.

  • 00:55:24 It makes a change, okay.

  • 00:55:34 Let's also check off database currently nothing else.

  • 00:55:36 picture

  • 00:55:37 and I will make that stupid music.

  • 00:55:54 It model and oh, we have an exception.

  • 00:56:04 connection Jesus boy

  • 00:56:08 why we have this on Earth.

  • 00:56:17 The client has disconnected English phone.

  • 00:56:26 Did you show me a smile?

  • 00:56:37 We got this Earth?

  • 00:56:39 I think this was related to

  • 00:56:50 my context

  • 00:56:52 Let's continue and see what happens.

  • 00:57:02 So let's try let's see what it says edit interesting why we got an error.

  • 00:57:11 Interesting less at the torch users.

  • 00:57:16 torch

  • 00:57:18 see first users

  • 00:57:21 Yeah, it is added we can also display the 30th as lecture 7 index and we can provide

  • 00:57:32 the user ID such as this or it is not working because we didn't Define optional parameters

  • 00:57:42 in.

  • 00:57:43 Oh, this is Dave why it is working with us commenting this art we have to make this a

  • 00:57:51 command.

  • 00:57:53 Yeah, and in our startup you are going to set an optional parameter as how was it?

  • 00:58:03 Let's say user ID or

  • 00:58:06 Let's make it smooth.

  • 00:58:10 I think he thought it doesn't matter but let's try so this will be an optional parameters.

  • 00:58:17 Okay like this.

  • 00:58:24 I'm going to putting it here now - yeah, we have put it in correct place.

  • 00:58:42 So this will be

  • 00:58:47 19

  • 00:58:49 comfortable action

  • 00:58:52 Let us this supposed option over concerns object doesn't token string pattern.

  • 00:59:00 So in the pattern we've arrived it, but how

  • 00:59:12 let's see not control the route option.

  • 00:59:25 Hey cuz like this year

  • 00:59:37 Action index or okay.

  • 00:59:39 So this is the whole pattern and then we will Define a user ID.

  • 00:59:46 I will also make this lower case.

  • 00:59:47 Here's what it will be like this.

  • 00:59:51 Okay, let's try.

  • 00:59:55 And see if it is working.

  • 01:00:03 You can see every query in executive.

  • 01:00:08 Here's these are related to mssql itself.

  • 01:00:12 And this is done by our application.

  • 01:00:18 Kate is getting loaded and here it is working as expected and now we can Define lecture

  • 01:00:29 7 index and tree.

  • 01:00:31 Yes, you see towards user is now visible.

  • 01:00:34 We can Define like this and second user is did visible as well.

  • 01:00:40 Let's change the torch user as something new and it would return Yes first use of a Jaso.

  • 01:00:51 Let's do this as lecture 7.

  • 01:00:56 And 30 of this year.

  • 01:00:58 We need to put index by the way.

  • 01:01:01 I can also Define lecture seven three.

  • 01:01:03 How can I do that?

  • 01:01:04 I will show you in a moment with the rotting.

  • 01:01:05 We will also refresh our memory.

  • 01:01:11 Yes working and let's add a rotating to index.

  • 01:01:15 As like this, okay routing or roach and here the template will be lecture seven.

  • 01:01:28 And now we will add an optional parameter as

  • 01:01:35 User ID, okay.

  • 01:01:36 Where can you post something like this if I remember correctly?

  • 01:01:45 So this will be lecture and not separate behalf of Got7 lecture and user ID.

  • 01:01:58 Let's try it.

  • 01:02:00 If it has a conflict of Rod, it will probably drove an average.

  • 01:02:03 Okay, so these eating pork?

  • 01:02:15 It's fine waitress.

  • 01:02:18 Yeah, like she was working and business is working as well.

  • 01:02:28 But this is broken default URL by

  • 01:02:34 pulled off.

  • 01:02:36 The roads are conflicting.

  • 01:02:40 It is start up perhaps.

  • 01:02:50 So some probably catch all the roads is being conflicted, but we can do as lecture and 3

  • 01:03:02 and it is what okay.

  • 01:03:05 let's add to our

  • 01:03:07 shortcut for now

  • 01:03:10 why this is conflicting.

  • 01:03:14 I wanted let's rest us like this.

  • 01:03:21 Okay, we can continue with our tutorial by the way.

  • 01:03:29 So this is how it is done.

  • 01:03:31 You see update using database we have already done that and this is web users those from

  • 01:03:38 database.

  • 01:03:39 We have done the same.

  • 01:03:41 I wonder if these days yes.

  • 01:03:46 This is still conflicting why trust me?

  • 01:03:51 Why default which URL it is calling it is you calling this URL?

  • 01:04:00 What if we change its here's what happens?

  • 01:04:10 I will just try something.

  • 01:04:31 Okay, this is working.

  • 01:04:39 So what we need to do is probably let's make this ass.

  • 01:04:44 lecture 7

  • 01:04:46 Okay, so this is the route and I am going to change the default route as well.

  • 01:04:57 So it will be a lecture 7 and

  • 01:04:59 patient index

  • 01:05:12 so let's change the pattern as

  • 01:05:18 like this.

  • 01:05:22 Yeah.

  • 01:05:26 I think now we should work.

  • 01:05:28 Let's try it.

  • 01:05:30 So this is the same as our root in the controller.

  • 01:05:41 So this is supposed to call the same URL I think.

  • 01:05:55 Yes.

  • 01:05:57 Okay, it is not working this way as well.

  • 01:06:02 What should bump like this?

  • 01:06:03 Evil moment.

  • 01:06:04 Yeah, this is working and he's also learning about this is not important.

  • 01:06:38 rustic

  • 01:06:59 I think I have another idea.

  • 01:07:02 so

  • 01:07:03 let's comment this art and add another route.

  • 01:07:12 Okay as

  • 01:07:13 Falls Village

  • 01:07:18 Let's see what happens.

  • 01:08:04 Okay now it is lucky.

  • 01:08:05 Yes.

  • 01:08:06 I think this is the best approach now we can set as we want to share such as like this.

  • 01:08:14 Okay?

  • 01:08:15 Okay, we have solved that problem as well.

  • 01:08:19 And now our form is working we can even do redirect we can add new users.

  • 01:08:26 You can do whatever you want.

  • 01:08:31 For example like this and Gigi EP.

  • 01:08:36 He's looking for his change it to URL.

  • 01:08:40 And you can also make like this and it will work as well after update.

  • 01:08:48 We can also return to same page and it will simply

  • 01:09:00 Require obtaining model and returning it.

  • 01:09:04 So how can we do that?

  • 01:09:06 We can do it with.

  • 01:09:11 I think I will change this refresh model.

  • 01:09:22 To this lecture 7 refresh model is voltage a model therefore simply.

  • 01:09:28 It failed composer model.

  • 01:09:32 and my model will be equal to

  • 01:09:36 this

  • 01:09:38 Just simply taking user ID.

  • 01:09:45 And then private sector 7 refresh model.

  • 01:09:51 It would Resort or model.

  • 01:09:55 like this

  • 01:09:57 But we also need to set.

  • 01:09:59 user ID of the model

  • 01:10:03 Yeah like this.

  • 01:10:10 Okay user ID.

  • 01:10:11 What is the user ID of a mother?

  • 01:10:13 boy

  • 01:10:15 when you can see the user ID, let's just cook list.

  • 01:10:34 from here

  • 01:10:36 Oh, this is different model.

  • 01:10:38 Yeah.

  • 01:10:39 Yeah, there is no user ID here.

  • 01:10:41 I am I was confused and after update users.

  • 01:10:45 I will just

  • 01:10:46 Make this like this.

  • 01:10:48 I don't know if I'm just returned.

  • 01:10:53 And we index action like this.

  • 01:10:58 I was just get model like here.

  • 01:11:09 Let's see.

  • 01:11:10 What hobbies.

  • 01:11:13 How will it behave?

  • 01:11:27 Okay, let's try.

  • 01:11:38 Let's add 50 users.

  • 01:11:42 change chest V5

  • 01:11:46 Okay, it has returned it the model we told us University which is the first Friday and

  • 01:11:57 you are the same so you are all didn't change and here it is so we can also replace model

  • 01:12:06 with the NIV user ID as well.

  • 01:12:09 yeah, you need to

  • 01:12:12 use this user ID.

  • 01:12:13 I think is interesting.

  • 01:12:18 Why it is important as expected.

  • 01:12:25 Let's try again 6.

  • 01:12:29 Just six okay.

  • 01:12:31 Okay, this is the Earth.

  • 01:12:47 Let's try again.

  • 01:12:56 My see it is not working because you see this form is returned, but

  • 01:13:13 it is calling lecture 7 update users.

  • 01:13:17 However, it is not fighting.

  • 01:13:26 And why might it be?

  • 01:13:31 Interesting.

  • 01:13:33 Let's try.

  • 01:13:35 you sure this is cool this probably

  • 01:13:45 post action lecture 7 update users

  • 01:13:50 Okay, this is retarded.

  • 01:13:56 Oh, maybe it was doing a cage.

  • 01:14:05 No.

  • 01:14:07 Okay, why update user is not being cold?

  • 01:14:18 Let's try here.

  • 01:14:23 Lecture 7 user ID optional maybe this is overriding other things.

  • 01:14:32 Yeah, probably we need to set this get only let's add some restriction to voting.

  • 01:14:43 We have seen that in.

  • 01:14:45 voting results

  • 01:14:47 He wrote in constraints and it will be get.

  • 01:15:09 restriction

  • 01:15:17 controller

  • 01:15:25 Okay, hold on.

  • 01:15:35 It's foolish.

  • 01:15:38 Okay, he ate his stupid posts.

  • 01:15:50 I actually results so we will make this as HTTP get.

  • 01:15:56 Okay, and this one will be HTTP post.

  • 01:16:02 Okay, so that's red stars and sea.

  • 01:16:07 the reason why it's working not probably this was all riding of

  • 01:16:18 post action

  • 01:16:21 You see you have to be careful with how you define the roads, okay?

  • 01:16:26 Since this is optional.

  • 01:16:30 I think it was catching always this one.

  • 01:16:38 Okay, let's see.

  • 01:16:42 I can't you got an address boy.

  • 01:16:51 I think it's definitely catching into this one.

  • 01:16:54 Let's try it.

  • 01:16:55 You see even though I called update user it is getting into this.

  • 01:17:05 And so I should give a different Road name to this.

  • 01:17:14 Or something like this perhaps if I Define it like this, I think it will be better.

  • 01:17:27 So it says

  • 01:17:29 Okay, so where is the arrow?

  • 01:17:31 Yeah, okay, it's fine.

  • 01:17:39 Can you say CTB post?

  • 01:17:48 Update user lecture 7.

  • 01:18:04 Yeah.

  • 01:18:11 Okay.

  • 01:18:18 Loading so let's let's make this a simple one as well seven use right here.

  • 01:18:29 I was just born.

  • 01:18:33 For example, yeah.

  • 01:18:37 Maybe we can also add eroding to this year.

  • 01:18:45 But then we need to Define loading all the rocky.

  • 01:18:48 I know I know I have to fix it.

  • 01:18:50 So this will be lecture 7, but we will have a rotor order.

  • 01:18:55 What is orders?

  • 01:18:58 It was inside here.

  • 01:18:59 Probably the order will be.

  • 01:19:04 Okay, too.

  • 01:19:07 And this will have another orders.

  • 01:19:12 as lecture 7 update users like here's

  • 01:19:20 this is the URL that we are going to post and this would have ordered one now.

  • 01:19:26 It should work.

  • 01:19:27 Yes, you see when they are conflicting you have to set orders and in the previous lecture,

  • 01:19:38 even though we have seen this until you try to solve a problem.

  • 01:19:43 It won't get into your mind permanently.

  • 01:19:49 So as you try to

  • 01:19:50 Twelve problems you will understand that courts or whatever you are working with.

  • 01:19:57 Okay.

  • 01:19:58 Now it is working and it will return model view.

  • 01:20:03 Yes, it says return it to our model.

  • 01:20:09 Let's try 7 test test Yugi.

  • 01:20:13 Yes, you see it has returned update user 7 this time and when we check it is here.

  • 01:20:20 That's another one 88 G GV P. Okay.

  • 01:20:26 It also return this one.

  • 01:20:28 Yes.

  • 01:20:29 It is determined that one.

  • 01:20:30 And we get yes, it's here.

  • 01:20:34 Okay, everything working.

  • 01:20:36 I will take a pause for a moment.

  • 01:20:41 Okay, let's continue with the tutorial so.

  • 01:20:47 This is regular forms.

  • 01:20:49 And with the regular asp.net now.

  • 01:20:54 We are going to see the beauty of asp.net MVC.

  • 01:21:01 A manually constructed form which will post the values to a method which will then read

  • 01:21:08 the values and assign it to an object all very basic and old school.

  • 01:21:14 However with asp.net MVC the concept of model binding was introduced.

  • 01:21:20 It allows your views to use information from the model to generate eg a forum for editing

  • 01:21:24 the model, but even more helpful that allows the receiving method on the controller to

  • 01:21:29 treat the posted values as an object of the models type instead of forcing

  • 01:21:33 You to read strings from the form in other words, you can now keep working with objects

  • 01:21:38 all the way through the communication between client and server.

  • 01:21:41 Thanks to the magic of model binding.

  • 01:21:45 Let's see how it works.

  • 01:21:46 Okay.

  • 01:21:47 So what we have seen was old school.

  • 01:21:49 This is the old school way of posting data and reading it refs receiving it now.

  • 01:21:55 We will see the model binding of MVC which is the new think new technology better technology.

  • 01:22:03 using model binding

  • 01:22:06 First we need a model.

  • 01:22:08 If you don't know what the model is.

  • 01:22:09 I suggest that you skip a few articles back and read up on it will create a simple model

  • 01:22:15 class for handling information about a user.

  • 01:22:18 Okay.

  • 01:22:19 We already have our model and we also know the bottom model is

  • 01:22:28 In our controller we can now pass an instance of this class to the view in a real world

  • 01:22:33 application.

  • 01:22:34 We would probably get the web user object from a database but to keep things simple.

  • 01:22:39 We just generate a new one for this demonstration.

  • 01:22:41 Okay, so, alright.

  • 01:22:44 This is the sample think let's add another page for model binding.

  • 01:22:53 And so they won't get confused and to do that.

  • 01:23:01 Let's we can still use lecture seven as our model and I am going to add a new view page

  • 01:23:10 here.

  • 01:23:12 I will call it as binding example or just finding okay binding says HTML and let's add

  • 01:23:22 a

  • 01:23:23 solar for binding

  • 01:23:24 Okay binding controllers.

  • 01:23:28 All right, and it will return binding but it wouldn't return binding because binding

  • 01:23:42 is on the lecture 7 we have to take it on The Binding if we want to return so let's

  • 01:23:50 add a folder as binding and let's move these into the binding.

  • 01:23:59 Okay, so I will make binding as a default route.

  • 01:24:05 I need CSS HTML.

  • 01:24:08 Oh, I don't even need to change that.

  • 01:24:12 Actually, let's continue.

  • 01:24:14 So this is II action result of simple binding but Hasty TB gets so we will be using the

  • 01:24:23 same URL

  • 01:24:25 Okay for HTTP get I action result and it will just return we have and it's going to return

  • 01:24:38 with the model.

  • 01:24:39 So our model is lecture 7.

  • 01:24:41 about to be able to use that model using

  • 01:24:45 okay.

  • 01:24:47 Victor 6 models

  • 01:24:50 Let's compose.

  • 01:24:52 Our model has lecture 7.

  • 01:24:58 And as our first name, that's our last name.

  • 01:25:04 Okay, and let's open our binding CSS HTML.

  • 01:25:15 By letting our view know what kind of model it can expect with the at model directive

  • 01:25:19 we can now use various helper methods more about those later to help with the generation

  • 01:25:24 of a form.

  • 01:25:25 Well just saw we need to know letnov rvf to know which model let's let it know.

  • 01:25:38 we could lecture 6 dots model starts picture 7 and we will use form of

  • 01:25:53 Using key?

  • 01:25:54 Okay, so we will be using okay and then

  • 01:25:57 what we are going to use using bar for equal to HTML that form.

  • 01:26:08 Begin form.

  • 01:26:09 Okay.

  • 01:26:10 We are using currently servers site variables after being informed.

  • 01:26:15 It's the method of HTML.

  • 01:26:19 So that has therefore I have to call it like this.

  • 01:26:26 Oh Jaden, we can have formatting even though it's a server-side currently.

  • 01:26:33 We are in server side because you see we have started with I mean razor scientists with

  • 01:26:39 ads and we are on in this Co so with the HTML label for okay HTML label for firstly or whatever

  • 01:26:53 so it says

  • 01:26:55 I'm not sad firstly.

  • 01:26:58 Do you know why it has allowed me to order the intellisense have shown me as our first

  • 01:27:07 name?

  • 01:27:08 Because I did set my model here and M is just anything it can be anything.

  • 01:27:13 It can be anything.

  • 01:27:18 So m is the short of modern therefore it is used, but it can be anything.

  • 01:27:24 It is fine.

  • 01:27:26 And so the first name and then HTML label for which will be m dot g like this.

  • 01:27:37 This is the linkage Scientist by the way last name and let's see what this will print to

  • 01:27:47 us.

  • 01:27:48 So I will change my default URL.

  • 01:27:51 Okay, and how am I going to do that?

  • 01:27:55 In the home controller of lecture seven.

  • 01:27:58 I am going to move this into a user control if I keep it what happens I want I keep it

  • 01:28:10 both.

  • 01:28:12 I will keep it here and here and I want to see what happens.

  • 01:28:17 They are conflicting but one of them will probably work first.

  • 01:28:23 I would repeal if it will throw an error is made throw it may cause a runtime errors.

  • 01:28:31 Let's see what happens.

  • 01:28:35 Because they are same.

  • 01:28:45 Okay.

  • 01:28:48 Yeah, it says and we just action exception because they are both being matched and

  • 01:28:56 Therefore I will remove the root URL of lecture 7 here and now it will be binding controllers

  • 01:29:08 root and let's see what it's going to return.

  • 01:29:12 I mean what it will I show on the

  • 01:29:14 sequin with this much of court

  • 01:29:20 So this level four is first name?

  • 01:29:23 I think it will generate a label named as first name.

  • 01:29:28 and then last name as such or

  • 01:29:32 oh, okay.

  • 01:29:34 I know the reason because we have used a different naming therefore.

  • 01:29:40 We need to return we've with the name of it.

  • 01:29:44 Okay, the name will be binding like this.

  • 01:29:55 Jake

  • 01:30:02 so this is the root URL rotating.

  • 01:30:06 if Microsoft

  • 01:30:08 Jay

  • 01:30:09 okay.

  • 01:30:10 You see as our first name is Starla last name and

  • 01:30:21 Let's add something between them perhaps.

  • 01:30:26 Okay, let's just copy paste here and then another div this time.

  • 01:30:33 Or this will be text box.

  • 01:30:36 Okay, so this will be take study or text box or text box for yet Xbox both.

  • 01:30:42 Yes box for

  • 01:30:46 and this will be for first name.

  • 01:30:51 Okay, so we are defining a textbox and the label for each variable and the last name.

  • 01:30:59 Okay, let's run the application to see so this will generate a new label as first name

  • 01:31:06 and the text box for the first name.

  • 01:31:09 You see this is a special text box, which will be bound to first name.

  • 01:31:14 We will also see that in the source code in a moment when the page loads.

  • 01:31:25 Okay.

  • 01:31:27 So the first name John it is coming from my model.

  • 01:31:31 And when I checked the source code you see input ID.

  • 01:31:35 First name name first name?

  • 01:31:36 So the name parameter is in is the important and it is named as the parameter name here.

  • 01:31:47 Let's continue and then input type submit.

  • 01:31:50 So the result will be very generous looking for but with labels and text boxes designed

  • 01:31:55 designated Post Properties of your model.

  • 01:31:59 Yes a

  • 01:32:00 Okay, and then let's continue by default.

  • 01:32:06 Let's let's read it quiet.

  • 01:32:10 Yes.

  • 01:32:11 By default the form will be posted back to the same URL that delivered it.

  • 01:32:15 So to handle that we need a post accepting controller method to handle the form submission.

  • 01:32:20 Okay, so by default it will post bake the same URL.

  • 01:32:24 What does that mean?

  • 01:32:25 That's open the code again and see so it will simply Prospect binding.

  • 01:32:31 However this time we will have another action handle it currently with the set or index

  • 01:32:40 action.

  • 01:32:41 HTTP get therefore when the post happens we can also have same action method HTTP post.

  • 01:32:50 Okay.

  • 01:32:52 So when I open the submit form, I will see that it is posting back to

  • 01:32:56 root URL OK root URL with post and then oh, by the way, it also has a request verification.

  • 01:33:09 It is automatically generated and now I am going to compose same index section with

  • 01:33:17 HTTP post

  • 01:33:22 it says

  • 01:33:25 so it doesn't allow me.

  • 01:33:41 I have same index therefore.

  • 01:33:47 I have to define a different thing.

  • 01:33:50 Public education results I action result simple web users.

  • 01:33:55 Oh, I see this time.

  • 01:33:57 We are changing the model because it is post.

  • 01:34:00 I mean changing the input because this time we are getting a lecture 7 type of model like

  • 01:34:07 this.

  • 01:34:08 Let's go with is mine.

  • 01:34:11 Since the signature of the method changes now, it is allowed.

  • 01:34:16 This will be HTTP post with same root here as you can see.

  • 01:34:19 And then we can update the values.

  • 01:34:27 So let's change this as updating values of our

  • 01:34:36 Database so let's copy and paste some code from here.

  • 01:34:46 I will just use the same.

  • 01:34:50 You see now I need to use this in another page as well.

  • 01:34:55 Therefore I will have.

  • 01:34:58 another this class is let's add a folder as

  • 01:35:05 not we don't even need a folder.

  • 01:35:12 Delete this.

  • 01:35:14 and then add

  • 01:35:16 just a class is named as

  • 01:35:21 okay public Global's.

  • 01:35:24 methods

  • 01:35:26 Okay, this will be a public static class for no need to initialize and inside this I will

  • 01:35:40 take.

  • 01:35:46 my method of

  • 01:35:48 refresh model here.

  • 01:35:52 It will now become public and to be able to select your seven.

  • 01:35:57 I have to include

  • 01:35:59 More than folders.

  • 01:36:03 Okay public external flash mode and it will now be a static.

  • 01:36:12 Okay, and now I can call it inside this as well.

  • 01:36:18 So it will be caused by global let us practice and here's

  • 01:36:31 okay, and

  • 01:36:36 Let's change this into Ash.

  • 01:36:39 Finding controller as well.

  • 01:36:44 So it will get a model with user ID 148 150 gives just user ID 1 and it will return binding.

  • 01:37:00 Finding and then same okay after post I will update the database.

  • 01:37:09 How am I going to do that?

  • 01:37:15 Simply?

  • 01:37:18 I will have an update methods I have cold out here.

  • 01:37:27 So what I need is I would also put this inside and another Noble Metals here.

  • 01:37:37 Let's call it as public.

  • 01:37:40 static void update users

  • 01:37:46 Jay and it will take or

  • 01:37:55 It will take.

  • 01:37:59 it need to take

  • 01:38:00 a model

  • 01:38:08 so it won't be like this exactly.

  • 01:38:13 Let's take this picture.

  • 01:38:15 Here this method will take a model.

  • 01:38:19 I mean an object of users like this nature 7 that my users.

  • 01:38:29 Okay, and

  • 01:38:30 okay, so why it oh, this will be tibia users type here.

  • 01:38:40 If you use this type my users.

  • 01:38:42 Yeah now it is working and we will call this method inside here as well.

  • 01:38:48 Jay Global method starts update users that my users

  • 01:38:55 Okay, that was just fun.

  • 01:38:58 We are going to apply same apply same how we gonna do that.

  • 01:39:08 We are going to do it like

  • 01:39:13 Let's do it here.

  • 01:39:14 So in our new okay here and instead of requests for now, we can use my model that it will

  • 01:39:21 come from our post back since we are doing a binding first name and

  • 01:39:27 Take this with you.

  • 01:39:32 See we are not using any more requests last name and user ID will be by default one for

  • 01:39:39 now and it will return the same.

  • 01:39:45 Okay, then all we have to pull up date.

  • 01:39:49 and that fish Okay, so

  • 01:39:52 I don't even need my model anymore.

  • 01:40:02 I think.

  • 01:40:06 Yeah, I need to call Global metal starts update users and provide my users.

  • 01:40:17 Then I can just return The Binding my model and I can also add a message that the update

  • 01:40:28 was successful to do that.

  • 01:40:34 Let's go to lecture 7 and add another parameter as pork string.

  • 01:40:40 Sr postmessage J. This will be by default Sloan I will set it here as my mother.

  • 01:40:54 that is our post message will be equal to a database or let's say

  • 01:41:06 User1 first name and last name?

  • 01:41:09 Okay, successfully updated

  • 01:41:11 And they tell me it's okay.

  • 01:41:16 So I will pass this message in the video if it is not known in The Binding here and I

  • 01:41:25 will just put it here and let's make it as if

  • 01:41:31 Model that's as our post message is not equal null.

  • 01:41:39 Let's party show it as either give and let's add a style.

  • 01:41:47 Okay for color or let's see colors of fold that and add models.

  • 01:41:56 That's our postage.

  • 01:42:00 Okay.

  • 01:42:01 And let's run application.

  • 01:42:02 Let's refresh the result.

  • 01:42:04 You see first one is Taurus University right now.

  • 01:42:09 We are supposed to see that on our screen and you see this is also object-oriented programming

  • 01:42:16 as well as MVC model view controller approached or methodology following programming.

  • 01:42:22 We are having objects classes for them and we want

  • 01:42:33 It's close this close this.

  • 01:42:41 on this one

  • 01:42:42 Okay, total Cinema updated to update it D be whatever you want.

  • 01:42:48 Let's submit.

  • 01:42:49 Okay, you see now we are also seeing the message as well.

  • 01:42:53 And you are on the same user Vault first name and last name successful updated in the database.

  • 01:42:58 These values are also updated and when we refresh the database we see update.

  • 01:43:03 Okay?

  • 01:43:04 Okay.

  • 01:43:05 It is working as supposed to be

  • 01:43:10 Notice how our controller action takes just one parameter of the same type as the model

  • 01:43:15 we passed into the view originally the web user class behind the scenes asp.net MVC will

  • 01:43:22 now process the form and assign the values found in its editable controls to the properties

  • 01:43:26 of the web user class.

  • 01:43:29 This is the magic of model binding.

  • 01:43:31 Actually there is nothing hidden magic when we inspect we are seeing an additional

  • 01:43:38 Parameter here.

  • 01:43:39 You see request verification token.

  • 01:43:41 Actually.

  • 01:43:42 This is where the magic happens.

  • 01:43:44 I mean the magic that it talks about be this one and the name here.

  • 01:43:50 It is binding at the court behind and if I delete this it won't work.

  • 01:43:56 Let's see so I have changed the value and let's see updated version to version 2 and

  • 01:44:02 I post let's see what happens.

  • 01:44:04 And I'm gonna fish which is working why interesting?

  • 01:44:15 Are there anything else?

  • 01:44:20 Probably it is reading these values here.

  • 01:44:23 So even deleting this probably won't change anything before we for submit.

  • 01:44:30 Let's try here working.

  • 01:44:35 So.

  • 01:44:37 Okay.

  • 01:44:38 So what is this doing interesting?

  • 01:44:43 However, if I change the names here, I am sure that it won't work anymore.

  • 01:44:48 Let's make them as like this and let's make these six submit.

  • 01:44:54 Yes.

  • 01:44:55 Now we are having another.

  • 01:44:57 okay says another of Courage why I couldn't because

  • 01:45:06 these values are no no.

  • 01:45:10 Okay, and the fish I will.

  • 01:45:14 Repost back and that's me.

  • 01:45:20 Try something else.

  • 01:45:22 I won't delete the verification, but just change the names and let's see what happens

  • 01:45:27 now.

  • 01:45:30 What you said so why we are getting an error here is at our binding controllers.

  • 01:45:40 It is reading null values.

  • 01:45:42 Simply.

  • 01:45:43 Well, let me show what I mean when I refresh it will do a post pic and you see these are

  • 01:45:48 null so it is expecting a model.

  • 01:45:51 But since we have changed parameter names now, they are not available.

  • 01:45:56 Therefore they are getting no and since we don't do a no check or application throughout

  • 01:46:03 Uncut address, okay.

  • 01:46:07 all right, so

  • 01:46:11 the summary

  • 01:46:14 Summary thanks to model binding you can maintain relations between your models and your views

  • 01:46:20 much easier in this article.

  • 01:46:23 We only scratched the surface though.

  • 01:46:24 There are a lot more possibilities with model binding as you'll discover in some of the

  • 01:46:28 upcoming articles.

  • 01:46:30 Okay, so I think today's lesson was

  • 01:46:36 Great and sufficient for up to now so I think we can end it but we before ending it.

  • 01:46:49 Let's take our notes of lecture cell context.

  • 01:46:57 Context then I will edit the ability to talk about final project.

  • 01:47:03 So in lecture 7 what we have seen

  • 01:47:09 So we have seen that.

  • 01:47:21 Okay.

  • 01:47:29 Okay.

  • 01:47:36 variations

  • 01:47:44 how to do

  • 01:47:53 rotting

  • 01:47:55 Okay, let's say how to do old school style forms action or scratch.

  • 01:48:20 Yes, forgot that.

  • 01:48:29 You see course.

  • 01:48:38 Okay.

  • 01:48:41 to update in search

  • 01:48:53 anytime

  • 01:48:56 action

  • 01:48:59 NSA

  • 01:49:02 So client service.

  • 01:49:10 communication

  • 01:49:16 Okay.

  • 01:49:22 Kitty

  • 01:49:28 Okay, I think.

  • 01:50:23 is enough

  • 01:51:11 all right, and

  • 01:51:18 if I say

  • 01:51:37 okay, I think this description is enough.

  • 01:51:53 One more thing.

  • 01:52:19 Let's upload our source code.

  • 01:52:21 But before do that, I will talk a little bit about project.

  • 01:52:26 So in there will be only a single semester project and you will get your whole score

  • 01:52:33 depending on this project.

  • 01:52:36 You are supposed to select your project yourself.

  • 01:52:41 For example, you are going to do an e-commerce website or

  • 01:52:44 I've been in management or Hospital management, whatever you want.

  • 01:52:50 You can use any programming language any database as well.

  • 01:52:55 But there is to rule actually several rules.

  • 01:53:02 I have ridden all of them.

  • 01:53:04 Of course.

  • 01:53:05 I am expecting MVC pattern from you.

  • 01:53:09 I am expecting.

  • 01:53:12 Responsive design we didn't get into design part yet with bootstrap, but we will eventually

  • 01:53:20 get that.

  • 01:53:22 So I am expecting responsive design.

  • 01:53:24 It doesn't have to be too good to be the full but it has to be responsive.

  • 01:53:30 It has to be useful and properly structured.

  • 01:53:34 So MVC pattern and responsive design.

  • 01:53:39 These are two mandatory things.

  • 01:53:40 You can do it with PHP as well if you can do but I'm not sure and we see person is hard

  • 01:53:46 to do with others programming languages as with that net cord is perfect for this as

  • 01:53:53 you can as you are already seeing so I suggest you to do with C sharp asp.net and as a as

  • 01:54:01 a database, you can use MySQL postgresql sqlite whatever you want, but mssql is also good

  • 01:54:08 with the Developer Edition.

  • 01:54:09 It is also free.

  • 01:54:10 to use for such projects and then since we are in pain de mie as you know, as in other

  • 01:54:24 courses that I gave you are going to make a recording of a video if you use ready quote

  • 01:54:33 blocks from internet, I want you to add a comment and put URL value have taken that

  • 01:54:39 code it is

  • 01:54:40 Low to take code from internet, but you have to reference to the source of that Court.

  • 01:54:48 Also, I want you to add enough synthetic data into your database to demonstrate the features

  • 01:54:58 of your application, whether it be for example, if you are doing a library management system

  • 01:55:04 than you should have hundreds of books with different categories and such or your

  • 01:55:10 if you are doing a patient management system, you should have patients doctors.

  • 01:55:15 So you need to fill your database with synthetic data or it can be real data as well and demonstrate

  • 01:55:23 how your application works.

  • 01:55:25 Okay.

  • 01:55:27 Also, not you are not supposed to only explain your source code.

  • 01:55:32 You have to run your application and show each future have they work?

  • 01:55:37 Exactly.

  • 01:55:38 Okay.

  • 01:55:39 This is really important.

  • 01:55:40 I

  • 01:55:41 In everything in this document.

  • 01:55:45 So if you still have any questions, feel free to ask me if you are not taking Mark.

  • 01:55:51 Hope my colors.

  • 01:55:52 You can still do a project and contact me to evaluate it by our Discord.

  • 01:56:00 It is fine totally fine.

  • 01:56:06 Because there are other people who watches my lectures and don't don't take my course.

  • 01:56:15 It is fine.

  • 01:56:16 You can still do a project and ask for help or for evaluation and let's upload our source

  • 01:56:25 code.

  • 01:56:26 so our GitHub repository

  • 01:56:30 Okay.

  • 01:56:31 You can also you should also use a quote management when you are doing your project such as GitHub

  • 01:57:23 it would be useful for you.

  • 01:57:26 Okay, I think everything is done.

  • 01:57:29 Let's check our GitHub and see if it is -

  • 01:57:37 okay.

  • 01:57:41 We will continue from data and the annotations.

  • 01:57:45 Hope for the next week.

  • 01:57:56 Okay.

  • 01:57:58 Okay, final project PDF is here.

  • 01:58:02 By the way, there is also one another important thing.

  • 01:58:06 You need to decide your project and get my approval before end of April.

  • 01:58:14 Okay, so decide your project and contact me by my email or by this court and tell that

  • 01:58:23 you are going to do which project and get my approval also project.

  • 01:58:30 We'll be done by each by solo.

  • 01:58:33 Okay in the previous years, none of the collaborative work worked.

  • 01:58:39 Well because one student does the project and others are just leeching they are doing

  • 01:58:46 nothing.

  • 01:58:47 Basically there for each project will be made by single student.

  • 01:58:53 Okay.

  • 01:58:54 I don't allow group workings in this course.

  • 01:58:57 Okay, that's it.

  • 01:59:00 Hope to see you next week.

Clone this wiki locally