Edit role in asp net core

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 108

  • @Dugz
    @Dugz 4 года назад +87

    Error open DataReader Solution:
    For anyone experiencing an error with their DataReader solution already being open the problem is that "userManager.Users" is not asynchronous. One solution to this is to extend it with the following: "userManager.Users.ToListAsync()" be sure to #include Microsoft.EntityFrameworkCore; in order to access this extension method.
    CODE FROM VIDEO WITH ERROR
    //foreach (var user in userManager.Users)
    //{
    // if (await userManager.IsInRoleAsync(user, role.Name))
    // {
    // model.Users.Add(user.UserName);
    // }
    //}
    NEW CODE WITH EXTENSION
    //foreach (var user in await userManager.Users.ToListAsync())
    //{
    // if (await userManager.IsInRoleAsync(user, role.Name))
    // {
    // model.Users.Add(user.UserName);
    // }
    //}
    A proposed solution for some is to add MultipleActiveResultSets=True; to their connection string however, if you're using MySQL Server instead of SQLServer this will not be available.

  • @arwahsapi
    @arwahsapi 5 лет назад +5

    You have reached beyond the pinnacle of tutorial arts. I, my dear friend, remain in awe.

  • @michaelt1349
    @michaelt1349 4 года назад

    Dugz: Good job!
    Saved me a lot of time.
    As I am using .NET CORE 3.1, I now tend to read all the comments to identify potential problems BEFORE implementing the code he used for .NET CORE 2.2

  • @standman007
    @standman007 4 года назад

    you are brilliant Venkat you have explained two concepts in one shot. Complete CRUD along with Identity. wonderful. wonderful. wonderful tutorial. thanks from the bottom of my hear

  • @mohannepal6503
    @mohannepal6503 5 лет назад +7

    It's been a week, we haven't seen any new video uploaded. WE MISSED YOU VENKAT.

  • @muhammadkamranmalik9614
    @muhammadkamranmalik9614 2 года назад +2

    foreach(var user in userManager.User) throws exception like DataReader connection already opened so kindly use foreach(var user in userManager.User.ToList()). Thank for great tutorial Venkat

    • @ghaziali3504
      @ghaziali3504 Год назад

      Thank you so much for this, I was having the exception, the DataReader connection already opened and I didn't know how to solve it your comment helped me. Keep posting these comments it really helps new developers. Shukriya

  • @_samirdahal
    @_samirdahal 4 года назад +15

    14:11
    you don't have to instantiate the list in the constructor in latest version of c#. You can easily do that in the property itself.
    public List Users { get; set; } = new List();

    • @eawig
      @eawig Год назад +1

      or even better, simply public List Users { get; set; } = new();

    • @rehmanmustafa3535
      @rehmanmustafa3535 Год назад

      @@eawig getting all users on a same role is making alot of issues for me. dont know y

  • @shuvo9131
    @shuvo9131 5 лет назад

    Thank u sir, I'm following this series and learning asp.net core everyday.

  • @conaxlearn8566
    @conaxlearn8566 4 года назад +9

    8:37 Why not just use
    var users = await _userManager.GetUsersInRoleAsync(role.Name);
    instead of retrieving all users and check them one by one if they are in the role?
    Or was GetUsersInRoleAsync not available when the video was created?

    • @ghost1black
      @ghost1black 3 года назад +1

      Good i think your method is best practice

    • @m3xpl4y
      @m3xpl4y 3 года назад

      Thank you, i was looking for this solution the whole time!

    • @hshlom
      @hshlom 3 года назад

      Excellent!
      This way prevents an error on this line -
      foreach (var user in userManager.Users)

    • @muhammadkamranmalik9614
      @muhammadkamranmalik9614 2 года назад

      @@hshlom userManager.Users.ToList()

  • @dullidddd
    @dullidddd 5 лет назад +6

    Please make tutorials on Docker and microservices in Asp.net Core.

  • @IllSkillz
    @IllSkillz Год назад

    there is an arror at




    When you add the disabled attribute to an HTML input element, it will prevent the input from being edited by the user. However, it will also exclude the input from being submitted with the form data when the form is posted. If you want to display the RoleId without allowing the user to edit it, you can use a readonly input instead of a disabled input.

  • @zkop1
    @zkop1 5 лет назад

    Done follow this tutorial in one week, best approach to learn this is you should read the tutorial on the kudvenkat tutorial website before u watch the video. so then u know the content of video, read is not enough must watch the video too. good luck.

  • @mhraamirali
    @mhraamirali 5 лет назад +4

    Admin role can't delete. Only admin can add or remove other roles. How admin set specific prevelig to other roles in asp.net core ? In this project admin can perform crud operation while other users can't. How to implement this?

  • @mahdiabbaszadeh9280
    @mahdiabbaszadeh9280 5 лет назад +3

    when you will finish asp.net core tutorials?

  • @SM-om6tw
    @SM-om6tw 3 года назад

    Thankyou for this awsome tutorial very helpful as always !

  • @mohammadrezamrg9380
    @mohammadrezamrg9380 5 лет назад +2

    thank you, it's not just a tutorial. it's complete learning of .net core. and is it possible to cover signalr?

  • @ashwinikumar9351
    @ashwinikumar9351 4 года назад

    Such a great video. I have been being a great fan of you. Sir

  • @KarMadz
    @KarMadz 5 лет назад

    Great video really appreciate the help! Currently implementing your tutorials in my major project. Thank you :)

  • @golodiassaid4879
    @golodiassaid4879 5 лет назад

    The best asp.net core tutorial out there! You're also the best educator imo. I guess next step is combing all these cool steps into complete asp.net project do it please :D

  • @emmanuelagbo7149
    @emmanuelagbo7149 5 лет назад +1

    many thanks keep them coming!

  • @rayt6867
    @rayt6867 5 лет назад +1

    Stupendous tutorial, you make it look so easy with a subject I had difficulties with. Many Thanks and keep them coming.

  • @muhammadwaqasiqbal8243
    @muhammadwaqasiqbal8243 4 года назад +2

    for some reason the tag helpers are not working for editrole! whenever i click on the edit button it doesnt throw an exception and the id is also not attached to the Url! can anyone help me with this?

  • @abidalisidd
    @abidalisidd 5 лет назад

    Thanks for the excellent tutorials.
    Please make a video on action based permission like add, edit, delete and view. Assign permission to user. Use permission instead of role or use both.

  • @nishanthmohan
    @nishanthmohan 4 года назад

    Even though text box ID is disabled for not allowing user manipulation, while updating the model ID is not taken from text box. Its actually taking from URL parameter. You can prove this by giving a different name RoleId instead of Id for EditRoleViewModel. The value will be NULL, because the control is disabled. Instead of disabled, use readonly to resolve this issue.

  • @phanidivi3613
    @phanidivi3613 5 лет назад

    god of teaching

  • @mahdiabbaszadeh9280
    @mahdiabbaszadeh9280 5 лет назад

    you're the best

  • @MrYanksfan1234
    @MrYanksfan1234 3 года назад

    Thanks for the great videos. Does anyone know why we show the role id to the user instead of just having it as a hidden input field to pass to the server?

  • @abdelfattahkhatab760
    @abdelfattahkhatab760 5 лет назад

    Great explanation !!!

  • @Manithan123
    @Manithan123 2 года назад

    Great tutorials as usual! Where can I find the source code for this course to download?

  • @nospam8262
    @nospam8262 4 года назад

    Can you share why we are not consistent with the original convention to use Interface repository, the naming convention of Index , Class under "Model" directory of the Table we are trying to create with [Required]
    [Display(Name = "City")]
    [MaxLength(50, ErrorMessage = "Field cannot be more than 50 Characters")] for example ?

  • @karanbirsingh2976
    @karanbirsingh2976 5 лет назад +1

    Really appreciate the way you have explained the .net core. Is this project available on GIT HUB? If yes please paste the project URL if you can.
    Thanks again.

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  5 лет назад +1

      Hello Karan - Very sorry, unfortunately at the moment, I do not have the code on Github. I will get it out there soon. In the mean time, please check out the following link where you can find the source code in text format Part by Part in logical sequence. Instead of typing everything by hand, you can copy and paste the code. Hope this saves at least sometime for you.
      www.pragimtech.com/courses/asp-net-core-mvc-tutorial-for-beginners/

  • @weihuang8905
    @weihuang8905 5 лет назад

    thanks, very good video u made!

  • @saurabhchauhan232
    @saurabhchauhan232 5 лет назад

    What will be next sir, what are you going to cover in next series ?

  • @krutishruparelia4221
    @krutishruparelia4221 2 года назад +1

    I am getting a null expectation error while using addtoroleasyn or any roleasyn method. Can any body help

  • @abhishomepage794
    @abhishomepage794 5 лет назад

    Hello venkut I applied autocomple jquery code and I was using WYSIWYG editor and now copy paste is not working

  • @TucumanoAburrido
    @TucumanoAburrido 2 года назад

    Hello, very good course. I have a problem." NotSupportedException: Store does not implement IUserRoleStore" the error ocurs in " if (await userManager.IsInRoleAsync(user, role.Name))". use NetCore 5. I would know how to solve this problem. Saludos desde Argentina.

  • @salmanchowdarym1110
    @salmanchowdarym1110 5 лет назад

    Thanks for your support

  • @hossammetwally07
    @hossammetwally07 5 лет назад

    Why are you getting in 4:30 the browser error while iam getting "Sorry, the resource you requested couldn't be found" the error we did handle in previous videos?

  • @JayJay-nb1sv
    @JayJay-nb1sv 4 года назад +1

    What is the music at the end of each video?

  • @reinoutko
    @reinoutko 2 года назад +1

    Because the id field is disabled it passes a null value when clicking on update.

    • @jgsk78
      @jgsk78 2 года назад

      thanks for this, I couldn't figure out why the model parameter for EditRole Post method doesn't receive the Id value... the readonly seems to be the correct keyword that works. Don't know why.. maybe different .net core version? I'm doing this on 3.0

    • @reinoutko
      @reinoutko 2 года назад +1

      @@jgsk78 I was using 3.1 and also used a readonly field

  • @mikejopia1294
    @mikejopia1294 5 лет назад

    hi sir, please make tutorials on CRUD using jquery dataTable asp.net core , please sir, thank you

  • @nguyentam5030
    @nguyentam5030 5 лет назад

    Thank so much

  • @nolimitsREAL
    @nolimitsREAL 4 года назад

    One thing I noticed, because I'm not using bootstrap. Every time when I try to Edit the role name, my roleId is null, I can't understand how that in your video is working and in my project isn't....

    • @nolimitsREAL
      @nolimitsREAL 4 года назад +1

      So I did find out why. This happens because of the "disabled" attribute from html. Try to use type=hidden, when your not using bootstrap. In bootstrap it's using a lot of javascript, so be carefull.
      Quote from w3schools: The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the element usable.
      Good luck and have fun. I hope it helps.

    • @reinoutko
      @reinoutko 2 года назад

      Use the attribute readonly instead of disabled.

  • @madanghimire1853
    @madanghimire1853 5 лет назад

    sir please make videos on jquery ajax call for this project

  • @abidalisidd
    @abidalisidd 5 лет назад

    How can we use ajax form in .net core?

  • @sarahjaved7185
    @sarahjaved7185 4 года назад

    When i try to implement this lecture i get this error
    ""there is already an open datareader associated with this command which must be closed first"
    On the line where we assign users in User field of editroleviewmodel
    Why is that

    • @dhanyadeeps
      @dhanyadeeps 3 года назад

      Modify the connection string to support multiple resultsets. Add MultipleActiveResultSets=true to connection string.

  • @cleartheory9854
    @cleartheory9854 5 лет назад

    Please add full, top-to-bottom view of the complete class, controller action, view, model

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  5 лет назад +1

      You can find the code in text format on our blog at the following link. For every video we have the source code. Hope this helps you save some time. All the best with everything.
      csharp-video-tutorials.blogspot.com/2019/01/aspnet-core-tutorial-for-beginners.html

  • @SaurabhKumar-om2gz
    @SaurabhKumar-om2gz 3 года назад

    I wonder How it works for everybody else without having actionmethod for Update Button.

  • @AbPoonamhi
    @AbPoonamhi 5 лет назад

    Unable to Load Users for Edit. Getting Error - There is already an open DataReader associated with this Command which must be closed first. at line "if (await userMgr.IsInRoleAsync(user, role.Name))" - Help is welcomed

    • @johnzika6505
      @johnzika6505 5 лет назад

      Look at
      @
      Murat Kazanova's comment. Fixes the issue.

  • @geetanjalisingh8614
    @geetanjalisingh8614 3 года назад +2

    one place I found so many unnecessary request are made to the database to fetch the user.
    var model = new EditRoleViewModel
    {
    Id = role.Id,
    RoleName = role.Name
    };
    // Retrieve all the Users
    foreach (var user in userManager.Users)
    {
    // If the user is in this role, add the username to
    // Users property of EditRoleViewModel. This model
    // object is then passed to the view for display
    if (await userManager.IsInRoleAsync(user, role.Name))
    {
    model.Users.Add(user.UserName);
    }
    }
    this foreach loop can be written making one request to the data base
    var Model = new EditRoleViewModel
    {
    Id = identityRole.Id,
    RoleName = identityRole.Name,
    };

    IList users = await userManager.GetUsersInRoleAsync(identityRole.Name);

    foreach(var user in users)
    {
    Model.Users.Add(user.UserName);
    }

  • @adamnoah121
    @adamnoah121 5 лет назад

    The views always shoot down so low towards the end towards these types of series.

  • @nagar80
    @nagar80 5 лет назад

    Hi Guys here is issue instead of disabled use readonly because if you use disable it didn't find the control and the id value could not post back to controller

    • @chetannavale2545
      @chetannavale2545 4 года назад

      Hello Ram, I am facing issue with non-posting of Role Id from View to Controller, it is null. I would like to know what you wish to highlight above by saying use readonly instead of disabled. Can you elaborate which piece of code I need to update to make it working?
      I face this same issue in begnining example of this .Net core series example as well.
      Thanks in advance

  • @aallal73
    @aallal73 3 года назад +1

    Hello i Have error with instrucution IsInRoleAsync
    foreach (var user in users)
    {
    if (await userManager.IsInRoleAsync(user, role.Name)) {
    model.Users.Add(user.UserName);
    };
    }
    InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.
    Does anyone have an idea?

    • @ZeeshanAli-sb5zk
      @ZeeshanAli-sb5zk 3 года назад

      i am also facing same issue

    • @shreyasudupas2007
      @shreyasudupas2007 3 года назад +2

      I have found out a solution for this.
      foreach (var user in _userManager.Users.ToList())
      {
      var isRolePresent = _userManager.IsInRoleAsync(user, role.Name).Result;
      if (isRolePresent)
      {
      model.UserNames.Add(user.UserName);
      }
      }
      here when you using IQuerable it keeps the connection open but IsInRoleAsync is trying to close the connection once it checks the users. therefore this issue comes up. If you follow the way I have done then you will not come up with issue.

    • @ghaziali3504
      @ghaziali3504 Год назад +1

      You need to .ToList( ) in the foreach loop
      foreach (var user in _userManager.Users.ToList())

    • @allalmohammed-amen6193
      @allalmohammed-amen6193 Год назад +1

      @@ghaziali3504 Thanks a lot

    • @ghaziali3504
      @ghaziali3504 Год назад

      @@allalmohammed-amen6193 you're most welcome

  • @tofayel_ahmed4754
    @tofayel_ahmed4754 2 года назад

    your blog is not working for this tutorial. please fix it

  • @التاريخ-ح4ظ
    @التاريخ-ح4ظ 4 года назад

    why use
    public EditRoleViewModel()
    {
    Users = new List();
    }

  • @NimbuYT
    @NimbuYT 4 года назад

    I'm getting error
    CS0246 C# The type or namespace name 'ApplicationUser' could not be found
    while adding it to constructor injection

    • @dacevedo19
      @dacevedo19 4 года назад

      Hey, something similar happened to me. Did you solve it?

    • @NimbuYT
      @NimbuYT 4 года назад

      @@dacevedo19 yes for me it was bcoz I was injecting IdentityUser class ...which we extended through ApplicationUser class refer to Part : 77

    • @dacevedo19
      @dacevedo19 4 года назад +1

      @@NimbuYT Yeah i fixed that now! Thank you brother! Great memory btw haha

  • @davidhambardzumyan2292
    @davidhambardzumyan2292 4 года назад

    Do you have this project on github?

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  4 года назад

      Hello David - The source code is not on GitHub, but you can download it from the following page. Hope this helps.
      www.pragimtech.com/courses/asp-net-core-mvc-tutorial-for-beginners/

  • @mahmoudnasser3581
    @mahmoudnasser3581 3 года назад

    disabled make id not posted so I think we should use readonly

    • @reinoutko
      @reinoutko 2 года назад +1

      I have the same problem, thanks Mahmoud!