ASP.NET Core MVC CRUD - .NET 6 MVC CRUD Operations Using Entity Framework Core and SQL Server

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there in this video we will create an asp.net 6 mvc application from scratch and we will perform crud operations on a sql server database using entity framework core this will be an amazing application for beginners who want to learn more about cad operations or if you want to refresh your memory using dot net 6 mvc let me take you through the app that we will create we will create a new dotted 6 application from scratch and it will be an mvc template and from this functionality over here we can add a new employee so let me give the details and once you have given all the details you can click on the submit button and on a successful submit it takes you back to the home page and you can change the details of an employee by viewing their details and you can see the details over here and you can change their details one or many and once you're done you can submit this button and their details will be updated as well if you want to delete an employee you can again go back to the view details and you can click on this delete button to lead delete their details i hope you like this video and if you do please hit the like button and subscribe to the channel to see more content like this one with that said let's get into it i have created a folder for myself in which i am going to create my asp.net 6 mvc crud application and i will open visual studio and first of all i will create a new project using this button from the templates page i will search for the mvc template and if you see over here we have an asp.net core web application but this one uses razer pages but we are interested in the mvc one so i'll scroll down further and until i find this one which says asp.net core web app and in brackets model view controller which is mvc so i will select this one and click next in here i will give a project and a solution name and also a location so i will copy this location path and then i will give a project name so i will call this one asp.net mvc crud you can give a different name as well and click next from here i will select the framework and from the drop down i will select dotnet 6 which is the latest at the time of this recording and i will keep the defaults as it is i don't need any authentication and i will configure this for https so i will click on this create button to create this application visual studio has created an mvc app for us and it has created a default controller and you can tell that this is an mvc app because it has the models view controller folders and also if you come to the program.cs file it is telling the services that you know i'm using controllers with views and also to the middleware we are giving the controller route and it has given a default route which goes to controller name slash action name slash id and that's optional as well and as a default value we are using the home controller and the index action in the home controller so if i go on to the controllers open the home controller and see the index action this is what it is showing when i first load the application so let's start the application to see what we get out of the box when we run our application we see this home page and it goes to home by default it doesn't show it in the url but if i say slash home slash index this is the same page which is the home page which comes to the screen by default when we run our application and we have a privacy page as well which is again in the home controller so we are going to make use of this home page and we are going to show the employee list over here and then perform crud operations in it i have come back to my application and we want to use entity framework core which is an orm and by using entity framework core we are able to talk to a database in this case we are going to use a sql server database and we are going to store and retrieve employee list from that database so in order to use entity framework we have to install it first and to install entity framework we are going to come here to dependencies right click on that and click on manage nuget packages in the browse section we will search for two packages one by one so i will first search and install this package which is microsoft dot entity framework core dot sql server so i will search over here this is the package so i will select and install this one by using this package we are we want to tell entity framework that we want to use sql server database so you know make our connections and we want to be able to perform cred operations using this package the second package that we want to install is this microsoft dot entity framework core dot tools package and this package is responsible for performing the migrations and migrations is basically when we want to create a new database or make changes to the database using our application that's where migrations now that we have installed these two packages it's now time to create a dbcontext class a dbcontext class is basically a class file which acts as a bridge between entity framework core and our database and using this class and the properties of this class we are able to talk to the database and perform the clutter operations so let's create this class first i will close this and i will create this class inside a folder so i will first create a folder i will call this data and inside this data folder i will create a class file [Music] and i will call this class file mvc demo db context we have created this class file and this dbcontext class file inherits from a base class which will be db context and this db context class comes from entity framework core so we have to pull in the dependencies i am going to press control dot to use this library which we have installed using microsoft.entity framework core and then we want to create a constructor for this class so a shortcut is if you come over here and click on this mvc context or whatever your class name is now press ctrl dot and use the generate constructor method with the options parameter so that you can pass the options back to the base class now that we have created the constructor it's now time to create a property and as i said earlier properties are used to access the tables that entity framework core will create in our database so i will create a property with the shortcut prop and then press tab twice and then you want to have this property as a db type of db set and then db set of something so we want to create a model which we will be able to use as in as a domain model or entity because we want to create employees and perform cred operations on employees so we will create an employee model so let's create an employee model so under models i can actually come over here and create a new folder called domain models or just domain because it's residing under models and then in the domain models i will add a new class and call this employee add that now we have we want to have a few properties for the employees and visual studio is suggesting one for me so we want an id but this will be of type grid which will be a unique identifier the next property i want is the name so let's tab to that and visual studio is smart enough to give me the name property after that i want the email let's say so prop its of type string and that will be the email property so the name of the property is email after that we can add salary so a property and i'm just keeping it as an int or a long here but you can use double or uh yeah you can use double and that should work fine so salary after that we can have the last property as a string property and we can say department so which department is this employee under and i can also have a date of birth property just to show date time as well and that will be date of birth so we have our properties defined for the employee domain model and this is what we want to persist in the database and then further retrieve the list of employees and a single employee as well so we are going to use this domain model inside our db context class so over here this dbset property will be of type employee and then i will use control dot to use this from the domain models over here and then we want a name for the property so i will call this employees and this will be the same name so this will be the table name that gets created ultimately from the ef code migrations now we have created this db context it's now time to inject this inside the program.cs file because otherwise our application would have no idea about the db context and what properties we want to create so we will open the program.cs file and after this add controller views method i want to add or inject this db context inside our services so i will use builder dot services dot add db context and that takes a type so i will give the type which is mvc demo db context and i will again press ctrl dot to use this from the data folder and after that it takes some options so i will press i will say options such that i will come to the next line options dot and i want to use it as in a sql server database this db context so i will say use sql server and press control dot again to use this from this library which is a microsoft dot entity framework core and this method use sql server takes a connection string as a string type so we can either hard code it over here or it is a good practice i'll just first close the brackets it's a good practice to get your connection string stored in the in the app settings.json so i will store this in the app settings.json and then retrieve it from here so first of all i will come over here and in here i want to create my connection string property so after the allowed hosts i will press comma and inside the double quotes i have this connection strings property and and the key value pair i want to define is the name first and then the value so the name for this one would be mvc demo connection string and the name is important later on i'll just tell you now but the value of this one would be something similar to this so we want to give the server information then the database information and then we want to specify that this is a trusted connection so trusted connection is equal to true so i will copy this and paste it over here and then i want to specify the values over here so the server that i have installed inside my machine is uh is called microsoft is is localhost slash this server name yours could be something similar or something different depending on what the instance name was when you were installing your sql server so i will use this name in the server property and then i want to give a database name and if i show you i'll connect to this and this is the databases i have so i don't have any database at the moment so i want to create a new database so whatever name you will give here gets created inside your sql server so i will give the name as mvc demo db and you can name it something different if you want to so now we have created the connection string and we can go back to our program.cs file and mention the connection string name over here so i will get the name from app settings by using builder dot configuration dot get connection string and then this takes a name as a string so the name of the connection string name is this if you have a different name use the name that you have in your application i will copy this and paste it over here i'll put this in a second line as well so we have injected our db context as well now it's time to actually run entity framework core migrations and create our new database so i will come to tools and i will go to nuget package manager and come to package manager console and over here i want to run two commands the first command that i want to run is this command which is add hyphen migration so i will copy this paste it over here and then i will put a space and then inside quotes i will mention the name to this migration so we are performing this for the first time because our database doesn't even exist so i will give this a name of initial migration and then press enter to start the migration process so behind the scene what's happening is it it is reading the employee.cs class because that's our dbset property and it is creating this as a migration so that we can use this migration later on to create a table inside sql server database so we have created a migration and we have a new folder over here which is migrations the next step we want to perform is to run the second command which is to actually update the database using this migration so i will come over here and paste this command update hyphen database and press enter and this will use the migration compare it to the database because the database doesn't exist it will actually run the commands to create the database so it has run the command successfully and if i show you i will refresh the list of databases and now we can see uh the mvc demo db appearing in our list of databases so we have the the new database created for us successfully using entity framework core the next step that we want to perform is to create a few pages from which we can create update delete and view all these employees and perform other actions on these employees so i can close these and i want to create a new controller and i will name this one employees controller so i will right click add a new controller and i will choose an mvcmt controller i will name this employees with the word controller dot cs in this controller i will have index methods so that i can show the list of employees but first let's add a functionality or let's create a functionality to add a new employee as well so we will start from there and then once we have an employee in our database then we will use that employee to show it in the list of employees that we want to show on the screen so the first action method i can actually just make use of this one and i want to create a method called add which will be used as employees slash ad to add a new employee and this will be the get method so i will decorate this with the http get method keyword [Music] and then also add a view for this so i will right click over here add a view and it's a razer view empty click on add and then i want to call this not index but add dot cs html [Music] and if you see over here in we have a new folder now inside the views folder which is employees and then inside the employees folder we have a new cshtml which is which is our razer pages template and then that's the name of the view is add ad view so we will use this view to add a new employee so to also now being able to navigate to this page i will create under the shared layout page i will add another tab along with the privacy and the home which will be called add employee and the controller name for this one would be employees because we have the employees controller and the action would be add action because we have created an action called add under the employees controller it's now time to run our application to see how it looks like and are we able to navigate to the add page or not so for that i will start my application and you can see we added a new list item in the nav bar so if i hover over this you can see on the bottom left hand side we are able to go to the employees controller and the add action so if i click on this one i get to a new page the url changed and the routing presents us the ad view that we created in the last few minutes so now we want to create a form from which we can add a new employee and because we are using bootstrap 5 we will make use of bootstrap classes so that we are able to make our ui pretty quickly so i'll search for forms over here and open this page [Music] and from this form i'll just select a basic form and i will copy this text and i will change it back in my in my application so i'll stop this and i will open the add dot cs html and in here i will paste this form now i want to get rid of these extra divs because we just want to copy the structure and not everything um and i will first start with the form so i want to tell this form that this is this is the method of post and then i also want to give an action to it so when this is posted it goes to the uh the add method so in our controller it goes to the add post method which we don't have at the moment but we will create one soon so it goes to the add action method and then we have a label so i'll remove this for a label for email address the first property we want the user to fill is the name and then this will come from a view model so let's create a view model first uh inside models i will right click and add a new class and i will call this add employee viewmodel click add and then i will have four properties in this one or maybe five but this properties would be similar to what we have as a domain model so i will copy all these properties but i will not copy the id property because i don't want my user to give me the id property i want to assign this created user a new id property so we will give that behind the scene so with these properties i want the values to be to be coming from the browser so with that i will come back to my cs html and on the top here define the model and then this will be coming from the newly created model that we have which is inside models and that's the add employee view model and now we can say after this we can say this is asp4 and we'll say name because it's recognizing that name is a property of this viewmodel so what value the textbox has it is assigning that property value to this name property similar to this we will have the email address and actually i'll change this from type email to text the second property is an actual email address and that's of type email and the asp for is email the third property that we will get from the user is let's see what we want to get is the salary so we will say or from the admin actually we'll say salary as the label and then this will be of type number and then this this will be for the property salary we want to add two more fields one will be for the date of birth so label of date of birth and then this is of type date and then the asp4 is for the property date of birth and finally it's the department field and we will have the label of department and asp for as department and type is just a text field and after that we have a button which is of type submit and we have this bootstrap classes given to it and it just says submit so we'll save that and we will run this application to see how our form is looking like and then we will create our post method inside the controller [Music] so this is loading up now and if i refresh this so you can see if i go to add employees i can see a name email address salary date of birth which is a date type so we get a date picker as well if you're using chrome and firefox or opera and you get a department field as well and that's nicely wrapped inside a container and i can also give it a heading so i'll add an h1 element and say add employee and maybe give a class to the form with a margin top of five so that we have some space between this form and the h1 tag um so it's hot reloading at this moment so now we can see our heading and some space in here as well so that's looking nice now we want when we submit the form we should be able to get the values here in a post method so let's create that post method now and i will stop the application and i will annotate this method with the http post keyword and i'll say public i action result the method name is add and this add method would require one parameter which will be the model itself so i will say this model and i will import the dependency from models and now i can give a name to this request object so i'll say request or we can say add employee request [Music] and now we can use this value to call entity framework core so that it can save our values to the database but before that we have to do a conversion from this model to an employee model so i will say where employee is equal to new employee [Music] and it's not a controller this is coming from domain models so i'll import that and i will give the id property because i want to assign this new uh employee a new id property so i will say a good new good and then the rest of the properties can be taken from the request object so name becomes name and then email is coming from is equal to add email add request dot email and then salary is coming from add employee request or salary then we have department which is coming from the request as well and then finally the date of birth with those fields we have our employee populated we have our entity or domain model ready and now it's just a matter of time to use entity framework core and specifically the db context to save this entity to the database for that because if you remember we injected this db context inside the services we are able to use this tb context inside the controller now so i will come over here and create a constructor so ctor as a shortcut and press tab twice and now we can inject the injected service here in the controller's constructor so i will say mvcdbcontext and use it this from the data give it a name and then i will i will say mvc as a name and then press ctrl dot to create an assign field so now i can use this private read-only field and talk to our database i will say this dot add and then i can pass this employee object to this actually before the ad i will say this dot employees dot add and then pass the employee over here like this and after adding the employee i want to save the changes so i will say db context dot save changes because if you don't do that entity framework doesn't save the changes to the database so you'll have to actually remember to use this line and once this has been done we will redirect our user to the index page which we don't have at the moment so we will just not do anything at the moment we'll just return the view for now all let's say return it to the add method so redirect to action [Music] uh the name of the action is add so we will just return this back to add for now and without even running this we can convert this method to an asynchronous method let's see how to do that we will add an async keyword over here and wrap this action result inside a task and now the structure is ready but to order to use the the add synchronous methods asynchronous methods we will use the add async method which is available to us and then we use the await keyword over here and also the save changes change to save changes async and because we are using an async method let's use the await keyword in front of it so now this method becomes totally in asynchronous and our form is calling this asynchronous method so let's start this application now to see if we are able to get the values or not and also i'll add a breakpoint so that we can see the values coming in our application has started so i'll come to the employee add employee page and i will fill some values here so i'll start with my name this is a fake email of course i'll give some salary and some date of birth [Music] and then a department let's say i t and if i submit i have a breakpoint over here it comes to the http post method uh of the add action so our form is working correctly if i hover over the request we can see all the values in the form now coming inside our uh form our post method so we can use these values and persist it in our database so i will go on this is converting our view model to our model and then asynchronously adding it to the database and i'll just continue from here so it reloads back to the page again and if i come to seed database our table should now have a new value so if i open the employees table our employees table now has a new row inside it which was added when we filled up that form so it's it's our add action is working correctly now now that we have a single entry in the database we can come back to our application and start the work on showing the list of employees on the main screen which is in the controller we'll have index action methods so i will minimize all of this and create an index method over here so that will be of type gate so i will decorate it with the http get keyword and i will write public i action result and the name would be index and this will be the list that we will show to the user and to show this list we need to talk to the database to get all the employees that we can that are stored in the database so let's make this method asynchronous first again we decorate it with the async keyword and wrap the i action result inside a task now we can use the private field db context to talk to the employees folder which is a property of this context class and then we want to get all the items so i'll use the to list async method which is not available to us right away so i'll use control dot and import the this library using microsoft dot entity framework core and now because this is an async method i will use the await keyword on it [Music] now we are getting the employees i'll store this inside a variable and we are getting the employees we want to display this uh into a view so we don't have a view at the moment so i will create a view right click on this action and add a view it's an empty view and the name of this method or the view is index.cshtml click on add i will remove these lines and actually i will add the model over here because we know the model it will be a list of type employees employee so i will use i will first import the employee from the models folder which is in the domain and then employee and it will be a list of that so a list of this employee and now it's time for us to use this and again similar to how we did before i'll use the h1 tag first to show that this is an employees list so employees and then after that i will have a for loop that can loop through this model and display all the employees in a table so i will first create a table and the table will have a class of type table which is a bootstrap class so we will use that and first of all we will start with the head section so t head and t head will have a single row so tr and tr will have a few headings which is th so the first heading would be id then we will have the name the email and then the salary the date of birth and finally the department and now we want to create the t body for the table so the t body will again have a tr but trs will be looped from all the results that are coming back from the database so i will start for each loop and sorry for each loop and the collection is the model and we'll say in the individual employee so employee in model and now we will start the row so tr will have a few tds namely these tds so td i will copy paste it a few times so the id of the first column is id so it will come from this employee dot id using the add symbol so employee dot id and similarly i'll have other employee details as well and the second column is name then we have the email after that we have the salary and then we have the date of birth which i will convert it to a string to string and i'll pass a format to that so let's say dd m yyyy or you can choose your own format as well and finally we'll have the department as well i will press ctrl k d to format this document and this way we are showing all the details coming back from the uh this database using the db context and we are passing it to the view so let's pass this model to the view so i will say return view and i will pass employees to it so let's see this in action i will run my application we have started our application but we don't have a page to see all the employees so we will quickly add that to the layout page and before the add employee button we will have a button which goes to the employees controller and open the or access the index method or action and the name for this would be employees save that and let hot reload to its magic and if we come back and refresh it actually didn't work so maybe it's still doing it i will press hot reload one more time and refresh the application and now we can see the employees page so if i click on employees it's it's talking to our database and getting the result back and displaying it on the screen correctly so as you can see it was very simple to fetch the data for the employees back from the database we only have a single employee and hence the single row and we also created the add functionality so we can quickly add another employee just to show you and we can also navigate this back to the employees page when this is a success so let's do that and see if hot reload works in that as well when the ad is successful we want to redirect it back to the index page so i will save that um and i want to press hot reload just one more time and here i will refresh my application and add a new employee let's say jason d and give it some salary and some date of birth and this is in the hr department so i will submit it and expect it to go back to the employees page if our hot readout was successful so i'll submit it oh i have a break point over here hence the time taken so i'll remove the break point and press continue and over here it saved the employee to the database and then it came back to the employees page and now we can see two employees in our list of employees so we have created two functionalities from the crud it's now time to uh you know able to access one of these items so that we can update them or delete them so for doing that we want to have a view button just over here somewhere so i will come back to the application and inside the index.html i want to add another heading with a space and a view button so inside the td i will have an anchor element and that is going to employees slash view and we also want to give the id to this one as well and i will just name this view and we want to give the id so the id to this would be employee dot id save that and you know just because i want to press this one more time so that it works correctly refresh this we have the view button and if we see down we can see the link as localhost 7262 slash employees slash view slash the id of that employee that we want to see now it's time to create that view action method inside our employees controller so i will come back to our application stop it this time and then inside the employees controller i want to add the view functionality so i will start with the get method [Music] and the function would be public i action result uh the name was view for the action method and this will have a good type coming in so a good with the name of id and let's see if that works correctly or not uh i will just have this and let's say return the view and also add this view because it doesn't exist at the moment it will be an empty razor page with the view name of view and i can close this for now and put a breakpoint over here and when i run my application i want to see if this id field is getting populated correctly or not we will go to the employees page and click on any one of the employees that we have so let's say i click on the second employee that is my name and if we see the id it's showing me the id for me let's compare it ends with 6e8 and if we go back to the database and execute this it ends with 6e8 so it's giving us the id to the employee that is my name and using this id you should be able to retrieve all the details of this employee from the database again so let's stop our application and work on that i will come into this method i want to retrieve a single employee this time so using the db context again i will talk to the employees table and get a single employee so i'll say first or default async and pass x such that x dot id is equal to the id that we are trying to fetch and this will return us a result so let's say employee and this employee could be an actual employee or it could return a null result because the id doesn't exist in the database so we will first check if employee is equal to null and you can check this over here or let's pass this directly to the employee to the view and let the view handle that and we'll say you know this employee doesn't exist or you can also just stay on the page and show an error so it's it's a lot of ways you can do it we will pass this to the employee and let the employee view handle it so now we want to go to the view and show this employee first and we will use not this employee but we will use a different view model this time because we want to have a segregation between the employee model and its view model so we will create a different view model i will add [Music] the a new class to the models folder and here i will say the update or let's say the update view model update employee view model and this will have similar properties of how we have in the employee so almost the same exactly the same to be honest because we also need the id property to come back so that we can check if the id exists or not and now using this model i can say at model and i will get this model from the models folder and this is the update employee view model now we want to add a form here as well and first display it but later on we would have to use a submit button to edit the form so i will go to the add view and copy this form because we can reuse a lot of it we will change the heading from add to edit employee and then this will be a post method the action would go to the view action or you can call it update as well but you know you have to change that in the controller as well so it will be the view action and we want another field which will be the id so we want the id over here as well as a first column which will be of type text but i will assign a read-only attribute to it so that the user is not able to change it and with that let's run our application again to see if it's able to populate and display the fields correctly or not but before we do that i think i'm missing a conversion here we want to not pass this employee object but we want to pass this update employee object so i'll create a new view model is equal to new update employee view model and the properties will be similar to what we had so i will use this and change it quickly so this will be employee dot id and then employee.name employee.salary department and date of birth and okay we got it so because this was an async method it's not allowing us to use it because we don't have it so we want to use the await keyword and also make this whole method as asynchronous and you know the drill async wrap this inside a task and now you can use the await keyword so using that we are able to get it and it's showing me this could be a potential error because the result from this method could be a null so we will say if employee is not null then do this conversion and then also return it return the view with this new variable otherwise we can just redirect this back redirect to action index for example so with those changes now we should be able to test our application i'll start this one we will go to our employees page and let it get the results from the database [Music] and let's view this employee so i'll click on the view button and it has gathered the data from the database again and it's displaying it nicely inside this form and we are able to update these fields and we should be able to add a new functionality so that it can take these updated values and return back to the employees page so let's create the functionality for the update method now i will come back to my application stop this one and have a post method for this view action so i will say http post and i'll make this async from the beginning so public async action result and this will be the action name view it takes the update model which is coming from the form that we saw and then we want to first convert this or we want to actually find if the id exists or not the one the one we are trying to change so we will say we will first try to get the employee from the database so employee is equal to using the db context so await db context employee dot you can also use the find method so i'll use the find async method and pass the primary key which is the model dot id and that way you should have an employee here and if you have an employee so let's say if employee is not equal to null then we want to actually update the values of this employee but not the id property but rest of the values so i will update the name from what's coming from this model and similarly the other fields as well so email becomes from the request email we have the salary which is coming from the model dot salary then we have date of birth which is coming from date of birth over here then we have the department which is coming from the department from this request so now we have updated our existing employee it's now time to save these changes so we will use the context mvcdbcontext dot save changes async and it's an async method so we will use the await keyword and using that we have saved the changes once that is all successful we want to return the user back to the employees page return redirect to action we want to return this back to the index page and if it doesn't work all right i'm just using the same uh if if you don't find an employee you'll have to send this to a to an error page showing telling the user that this employee was not found but i won't be covering that at the moment so with that you should be able to you know update the employee we are getting an error over here uh it's saying since this is an async method um must be an i action result rather than a type of i action result so we want to make use of the await keyword and then run this view as a task so task dot run and then use the method like this and close the bracket as well so using that we are running this task and also provide the name of the view so we'll say the view is view save that and now if we run the application let's test if we are able to view and change the details for this employee or not so now we want to go to the employees page and pick an employee that we want to change we'll use this top one and in here i want to change a few details let's say jason d becomes jason devon and then change the email as well maybe change the salary and let's decrease the salary um change the date of birth and just confirming that you know we all the changes are reflected back in the database and let's change the department from hr to human resources and now if we click on the submit button it's gone back to the database to change the you know make the changes and save it and now you can see the reflection of those changes as well so if i show you the database refresh this one more time and now we can see that the data the changes have been are reflecting now in the database as well so our update functionality is working it is now time to work on the final part of the club operations which is the delete functionality so for that i will come back to my application and we want to add a delete button on the view page so when we are able to see the details we want to add another button so i will copy this button and paste it over here this will be again of type submit and the class for this one would be a danger class so that it shows up in red and we want to give an asp action and an asp controller for this one but before we do that i will also change the name the value of this button will be we'll call this delete so that it's clear that it's the delete button and we want to add these two informations here but before that let's create a new action method inside the employees controller so after the view i will add another post method http post and i will use public the same as above async task of type i action result and then i will call this method delete and delete method would take the same form view model because the forms ideally the same we want to take in the view model and we want to use the id property from this view model so i want to define i want to take this id property go to the context and tell it to delete so i will say i will first fetch the employee so employee is equal to and use the context i will say mvc mvcdbcontext dot employees dot find and i will pass the id model dot id and we'll use the async version find async and use the await keyword over here now if we are able to get the employee so if employee is not equal to null then we will delete this employee so we will tell db context to remove this employee so employees dot remove and then we will pass this found employee complete to the remove method and after removing it we have to save the changes so we will say await and we see db context dot save changes async and with that our employee will be removed and after that we want to redirect it back to the employee list page so that we can see what are the remaining employees left so return redirect to action and we want to redirect to the index page index action method and that's it and if the employee was not found i will still just go ahead and display the action method index so with those changes i can come back to the view page and now fill in these details so on this delete button i want to talk to the employees controller and call the action method delete save these changes and run our application we'll go to the employees page and we will delete this json employee so i will view this employee and click on the delete button and it has deleted the employee and returned the result back to the employees page and we only have one employee left so if i show you the database it was showing two employees now if i execute this query again it's only showing one employee that is left so we have successfully implemented the delete operation as well we saw how easy it was to implement crud operations in an asp.6 mvc application if you like this video please hit the like button and subscribe to the channel to get more content like this one thank you for watching and i will see you all in the next one
Info
Channel: Sameer Saini
Views: 133,573
Rating: undefined out of 5
Keywords: asp.net mvc crud, step by step tutorial on asp.net mvc crud, asp.net mvc, asp.net mvc tutorial, asp.net core mvc, asp.net mvc project, asp.net mvc tutorial in hindi, asp.net mvc project start to finish, .net 6 mvc, asp.net core mvc 6 tutorial, asp.net core mvc tutorial kudvenkat, asp.net core mvc sql server, asp.net core mvc crud operation with entity framework, asp.net 6 mvc, asp.net 6 crud, mvc crud operation example in asp.net c#, mvc crud operation using entity framework
Id: 2Cp8Ti_f9Gk
Channel Id: undefined
Length: 58min 51sec (3531 seconds)
Published: Fri Jul 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.