ASP NET Core Model Binding

Sdílet
Vložit
  • čas přidán 3. 04. 2019
  • In this video we will discuss Model Binding in ASP.NET Core with examples.
    Healthy diet is very important for both body and mind. We want to inspire you to cook and eat healthy. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking.
    / @aarvikitchen5572
    Model binding maps data in an HTTP request to controller action method parameters
    The action parameters may be simple types such as integers, strings, etc or complex types like Customer, Employee, Order etc.
    Text version of the video
    csharp-video-tutorials.blogsp...
    Slides
    csharp-video-tutorials.blogsp...
    ASP.NET Core Text Articles & Slides
    csharp-video-tutorials.blogsp...
    ASP.NET Core Tutorial
    • ASP.NET core tutorial ...
    Angular, JavaScript, jQuery, Dot Net & SQL Playlists
    czcams.com/users/kudvenka...
  • Věda a technologie

Komentáře • 106

  • @MosquitoMurderer
    @MosquitoMurderer Před 5 lety +26

    I love when you say: "red squiggly"

  • @robsonsilva9490
    @robsonsilva9490 Před 2 lety +1

    Great! I'm from Brazil (we wrotes Brasil), and yours tutorials was help me learn more times that I'can remember! Thank you!

  • @vinayakh7730
    @vinayakh7730 Před 5 lety

    Thank you Venkat sir, you are awesome!

  • @huseynmikayil5119
    @huseynmikayil5119 Před 5 lety +8

    You are the best tutor I've ever seen.

  • @jvusa
    @jvusa Před 3 lety

    Excellent sir, Thanks a lot for Detail explanation....

  • @dheemanthanand731
    @dheemanthanand731 Před 4 lety +1

    Sir. Thank you very much for in detailed explanation.
    I have a doubt here,
    how is it even able to remember the created data between states in the current tutorial,When I navigate to Index method it still retains the new created data and the same is retained in every state.as we have learnt that its stateless.

  • @saranyasaran1916
    @saranyasaran1916 Před 4 lety +2

    Sir , your videos are always great and I have never seen a tutor like you. You are really great. And I love the music gets played end of the every videos of this series simply nice and soothing.

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  Před 4 lety

      Hello Saranya - Thank you very much for the feedback. Means a lot. I have included all the .NET core tutorial videos, slides and text articles in sequence on the following page. Hope you will find it handy.
      www.pragimtech.com/courses/asp-net-core-mvc-tutorial-for-beginners/
      When you have some time, can you please leave your rating and valuable feedback on the REVIEWS tab. It really helps us. Thank you. Good luck and all the very best with everything you are doing.

    • @chessgamesonline5867
      @chessgamesonline5867 Před 2 lety

      its confusing.

  • @yasirirfan5262
    @yasirirfan5262 Před měsícem

    brilliant explanation.

  • @mertkurt947
    @mertkurt947 Před 10 měsíci

    you are awesome teacher , thank you

  • @coolwaterdvr
    @coolwaterdvr Před 5 lety

    Thanks Venkat.

  • @turhansaltas9284
    @turhansaltas9284 Před 4 lety

    you are the king brother.

  • @AbuSayed-gf8gt
    @AbuSayed-gf8gt Před 2 lety

    Great tutorial !

  • @cesareemauritanie5288
    @cesareemauritanie5288 Před 4 lety

    Top Thank you !!!

  • @sakthir3892
    @sakthir3892 Před 5 lety

    Sir, nice explanation

  • @RicardoJnfrazao
    @RicardoJnfrazao Před 2 lety

    Great tutorial.

  • @naodagere8210
    @naodagere8210 Před 4 lety

    Thank you very much.

  • @roadtripping
    @roadtripping Před rokem +1

    How does the repository store information? Because we used AddSingleton for the Employee repository service. AddSingleton maintains state. If we hadn't, without the use of a database, session variable, etc. the new employee added would have been immediately lost upon clicking create.

  • @eugene-white-shark
    @eugene-white-shark Před 2 lety

    Thank you!

  • @oleksandr8923
    @oleksandr8923 Před 4 lety +8

    I received NullReferenceException because I had AddTransient method in startup.cs instead of AddSingleton. After I changed it the create button started working well, hope it will help someone

  • @yashaswikeote7689
    @yashaswikeote7689 Před 5 lety +4

    Please make video on azure DevOps

  • @codeautomate8155
    @codeautomate8155 Před 5 lety

    thank you

  • @RachitJain4U
    @RachitJain4U Před 3 lety

    Thanks Sir :)

  • @saidamir4268
    @saidamir4268 Před 3 lety

    Thank you.

  • @grandmagus8618
    @grandmagus8618 Před rokem

    question , when you are creating view is that where you bind model or it can automatically understand when controller takes "Student" as parameter to assign model to it . is not view responsible to model binding?

  • @salmanchowdarym1110
    @salmanchowdarym1110 Před 4 lety

    Thanks

  • @AbdullahTaherAbubakar
    @AbdullahTaherAbubakar Před 4 lety +2

    Great Lesson As Always...
    One Question Though : Every time you add a new employee (object) to the list; the list gets updated even after you do the redirect. The question is where is the list get stored?..is it cached or what? #kudvenkat

    • @javaguitarist
      @javaguitarist Před 4 lety +2

      It probably has to be just in memory. When he gets into the database model, you will see how it is inserted into the database where you can see it. If you close the solution and reopen it, new users do not persist.

    • @apositron84
      @apositron84 Před 4 lety

      Yes! I was confused about that as well. Voodoo!

    • @peritusdemi5028
      @peritusdemi5028 Před 4 lety +3

      In your " Startup.cs " class you have added a service "services.AddSingleton();"
      This AddSingleton is responsible for caching your data in your browser. If you delete the cache, your added data will also be removed.

    • @AbdullahTaherAbubakar
      @AbdullahTaherAbubakar Před 4 lety

      @@peritusdemi5028 Thank you for making it even clearer.

    • @anuyajoshi4360
      @anuyajoshi4360 Před 4 lety

      @@peritusdemi5028 - Thank you for sharing this information.

  • @HungVo-fp7xk
    @HungVo-fp7xk Před 4 lety

    I'm confused one thing that why in the controller we perform everything in the interface but not in the actual object? we have IEmployeeRepository is an interface and MockEmployeeRepository is an object class that implements that interface. Why we don't instantiate the object in the controller but just the interface? New to C# sorry

  • @mp-ot7fw
    @mp-ot7fw Před 5 lety

    I need some suggestions. I have been following along learning a lot. This is the first time I have gotten stumped.
    My Create Post action does not seem to be getting to the HomeController Post method. There are no build errors. Output shows a lot of threads exiting with error code 0.
    I have tried putting Break points on both the Get and Post HomeController methods. The HttpGet Create method is being hit, the HttpPost Create method is not.
    How can I further debug this?
    Thank you very much. BTW I am using VS 2019 Core 2.2

    • @mp-ot7fw
      @mp-ot7fw Před 5 lety +1

      Nevermind, it was my html. I changed the button for an input type="submit". Works great! TYVM for these tutorials!

  • @kennethcheung4911
    @kennethcheung4911 Před 4 lety

    Are there benefits to save it to an separated newEmployee object instead of below code?
    _employeeRepository.Add(location);
    return RedirectToAction("details", new { id = employee.Id });

  • @preetijuyal1742
    @preetijuyal1742 Před 4 lety

    hi @KudVenkat sir, it would be very helpful if a concept is explained with respect to previously used concepts and techniques in place of this concept and technique to achieve a particular functionality and how this concept is implemented in various languages.

  • @reneh5
    @reneh5 Před 4 lety +2

    In my case the ViewModel object has all its attributes with null value, not a single value I entered shows on it

  • @giokavlashvili7003
    @giokavlashvili7003 Před 4 lety

    Hi Venkat, What is the lifetime of the _employeeList object after creating and adding new Employee object to it?

    • @lukedodson3441
      @lukedodson3441 Před 4 lety

      Think it's just until the app is closed since its only a mock repository.

  • @heemelhimaddri534
    @heemelhimaddri534 Před 5 lety

    Sir, actually I want to learn asp.net but I can't take any decisions till now because of some hesitations.
    should I need to start with asp.net or asp.net core ?

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  Před 5 lety +3

      Hello Wag - ASP .NET Core is a new technology from Microsoft. However, there are still plenty of opportunities with ASP .NET MVC. Lot of ASP .NET MVC concepts are also relevant in ASP .NET Core. So I suggest learn both ASP .NET MVC and ASP .NET Core to expand your skill set. Hope this helps.

    • @sanjuds1
      @sanjuds1 Před 3 lety

      @@Csharp-video-tutorialsBlogspot Hello Sir , whether model binding in asp.net mvc same as asp.net core model binding.

  • @ravichandragangavarapu1259

    Sir u said everything about mvc by using asp dot net core

  • @pranavsinha9821
    @pranavsinha9821 Před 4 lety

    Hi Venkat ,Department value (drop down value ) is going null with httppost. Could you please help.

  • @anuyajoshi4360
    @anuyajoshi4360 Před 3 lety

    Thank you for tutorial. While practicing the session I came across an issue , Parameter ID never receives value , it is holding null value even though Create method has all required details. below is code snippet:
    public HomeController(IEmployeeRepository employeeRepository)
    {
    _employeeRepository = employeeRepository;
    }
    [HttpPost]
    public RedirectToActionResult Create(Employee employee)
    {
    Employee newEmployee = _employeeRepository.Add(employee);
    return RedirectToAction("Details", new { id = newEmployee.Id });
    }
    [Route("[Controller]/[action]/{id?}")]
    public ViewResult Details(int? empId)
    {
    HomeDetailsViewBased homeDetailsViewBased = new HomeDetailsViewBased();
    homeDetailsViewBased.Employee = _employeeRepository.GetEmployee(empId ?? 1);
    homeDetailsViewBased.PageTitle = "Employee Details";
    return View(homeDetailsViewBased);
    }
    Any guidance how to overcome empId receiving null will be helpful using .net core 3.1

    • @conaxlearn8566
      @conaxlearn8566 Před 3 lety

      In the Route you have {Id?}, but in the method parameter you called it 'empId' instead of 'Id'.

  • @marcol5374
    @marcol5374 Před 4 lety +1

    Hello Master, please explain me when exactly the new object as a parameter to Create(Employee employee) has been created? In the Create.cshtml file we map the property to an object of a Class Employee but i can't see the new object.
    Thanks a lot

    • @marcol5374
      @marcol5374 Před 4 lety

      Automatically created by Model Binding !

    • @peritusdemi5028
      @peritusdemi5028 Před 4 lety

      Run the Create(Employee employee) method in debug mode, and follow your code line by line. You will understand how the object have been created.

    • @marcol5374
      @marcol5374 Před 4 lety

      @@peritusdemi5028 of course but in the code there isnt any new keyword. The object is automatically created by model Binding and passed to the Create method

  • @CrivatFlorin
    @CrivatFlorin Před 3 lety

    How the heck is .net core doing that? Where does the info submited in the form gets stored? In memory? For how long?

  • @aarbiayaz4744
    @aarbiayaz4744 Před 4 lety

    can anybody explain why do I need to change add transient to singleton?

  • @sunnysharma5635
    @sunnysharma5635 Před 2 lety

    Make one tutorial for web api using asp. Net core

  • @codeautomate8155
    @codeautomate8155 Před 5 lety +1

    null reference exception is occured when press create button
    how can i solve it?

  • @pablosalas8586
    @pablosalas8586 Před 4 lety

    Can someone explain to me why it created a new employee without using the instance or the keyword "new", just added it? thx

    • @peritusdemi5028
      @peritusdemi5028 Před 4 lety

      This is created in your MockEmployeeRepository class with it constructor.

  • @user-kr9gm6pi6w
    @user-kr9gm6pi6w Před 4 lety +1

    How to fix the error:NullReferenceException. I already use AddSingleton.But Constructor I use with _employeeRepository = new MockEmployeeRepository();

    • @harag9
      @harag9 Před 4 lety

      Check you have the below code in the Startup.cs file in the method "ConfigureServices" --
      services.AddSingleton();

    • @mdsaddamkhan8400
      @mdsaddamkhan8400 Před 4 lety

      I have the same code but can't help it.

  • @jazicasri9248
    @jazicasri9248 Před 4 lety

    NullReferenceException: Object reference not set to an instance of an object.
    AspNetCore.Views_Home_Details.ExecuteAsync() in Details.cshtml
    +
    Name:@Model.Employee.Name
    sir help me to clear this error

  • @christianloperadecastro4875

    An unhandled exception occurred while processing the request.
    NullReferenceException: Object reference not set to an instance of an object.
    NullReferenceException: Object reference not set to an instance of an object.
    AspNetCore.Views_Home_Details.ExecuteAsync() in Details.cshtml
    +
    @Model.Employee.Name
    //I receive this error message. Can you show some solution for this.Thanks you

  • @mohammadhilal8508
    @mohammadhilal8508 Před 4 lety

    sir, when i add employee and next time when i restart the application it does not show me the added employee. what would be the reason pls help me.And it also does not add employee to my list.

    • @navinbadlani9211
      @navinbadlani9211 Před 4 lety +1

      When we are restarting our application MockEmployeeRepository constructor is getting called and list is reset to that 3 items which we are adding inside constructor and once application starts so we can add more items through create option but that newly created items will be there till the application is running once we restart it will again come back to original list

    • @mohammadhilal8508
      @mohammadhilal8508 Před 4 lety

      @@navinbadlani9211 okay, I got it and thanks for the reply. So what we can do to overcome it.

    • @naodagere8210
      @naodagere8210 Před 4 lety +1

      @@mohammadhilal8508 We will use SQL database and I hope he will cover that part in the coming slides

    • @peritusdemi5028
      @peritusdemi5028 Před 4 lety

      Use this in your constructor:
      public HomeController(IEmployeeRepository employeeRepository)
      {
      _employeeRepository = employeeRepository;
      }

  • @ShivamSingh-oe8tz
    @ShivamSingh-oe8tz Před 3 lety

    I'm getting redirected to "create/home" instead of" home/details/id" can anyone tell why!

  • @lukedodson3441
    @lukedodson3441 Před 5 lety

    @Model.Employee.Name is null apparently. The Add function doesn't seem to be working for me

    • @MukundPatel
      @MukundPatel Před 5 lety

      did you get reason and solution? I am facing the same issue. so please share with me.

    • @lukedodson3441
      @lukedodson3441 Před 4 lety +1

      @@MukundPatel home controller constructor needs changing

    • @lukedodson3441
      @lukedodson3441 Před 4 lety

      @@MukundPatel you get it working?

    • @peritusdemi5028
      @peritusdemi5028 Před 4 lety +2

      The constructor of the MockEmployeeRepository class already has a new employee list object. So you don't need a new MockEmployeeRepository in HomeController constructor. So use this in your HomeController constructor instead:
      public HomeController(IEmployeeRepository employeeRepository)
      {
      _employeeRepository = employeeRepository;
      }

    • @mdsaddamkhan8400
      @mdsaddamkhan8400 Před 4 lety

      @@peritusdemi5028 I did the same thing but it could not help

  • @lukedodson3441
    @lukedodson3441 Před 5 lety +1

    Got a null reference exception

    • @Pasaaydaan
      @Pasaaydaan Před 3 lety

      I am also getting null reference exception

    • @lukedodson3441
      @lukedodson3441 Před 3 lety

      @@Pasaaydaan change the Home Controller constructor

  • @hossammetwally07
    @hossammetwally07 Před 4 lety +1

    NullReferenceException: Object reference not set to an instance of an object.
    AspNetCore.Views_Home_Details.ExecuteAsync() in Details.cshtml

    • @lukedodson3441
      @lukedodson3441 Před 4 lety

      Change the HomeController constructor

    • @edmond1314
      @edmond1314 Před 3 lety

      @@lukedodson3441 Inconsistent accessibility: parameter type 'IEmployeeRepository' is less accessible than method 'HomeController.HomeController(ILogger, IEmployeeRepository)

  • @lukedodson3441
    @lukedodson3441 Před 5 lety +1

    Fixed it haha

  • @chessgamesonline5867
    @chessgamesonline5867 Před 2 lety

    A bit confusing. :)

  • @user-kr9gm6pi6w
    @user-kr9gm6pi6w Před 4 lety +1

    Who have error.
    public HomeController(IEmployeeRepository employeeRepository)
    {
    _employeeRepository = employeeRepository;
    }

    • @harag9
      @harag9 Před 4 lety

      You shouldn't be getting at this point if you had been following all 40 videos, no change here in this video - It would also help if you actually said what error you're getting.

    • @naodagere8210
      @naodagere8210 Před 4 lety

      Thanks. This has solved the NullReferenceException error

    • @peritusdemi5028
      @peritusdemi5028 Před 4 lety

      Thanks, from this video, your proposed method is working. solving the NullReferenceException error

    • @mdsaddamkhan8400
      @mdsaddamkhan8400 Před 4 lety

      I have

  • @himanshudashore3866
    @himanshudashore3866 Před rokem +2

    I got this error
    NullReferenceException: Object reference not set to an instance of an object.
    AspNetCore.Views_Home_Details.ExecuteAsync() in Details.cshtml, line 9
    Line no. 9 code is : @Model.Employee.Name