ahmed salah

ahmed salah

  • 1.9k
  • 328
  • 20.5k

How to allow cell on data table for edit and close after edit ?

Jun 9 2023 5:40 PM

I work on asp.net razor page model . i face issue i can't edit datatable on same page by edit cell without redirect to another page

I need to edit cell on same page 

my code details as below :

public class UserModel
    public string Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    // add other user properties as needed

public class IndexModel : PageModel
    private readonly YourDbContext _dbContext; // replace with your DbContext class

    public IndexModel(YourDbContext dbContext)
        _dbContext = dbContext;

    public List<UserModel> Users { get; set; }

    public void OnPost(string userId)
        Users = _dbContext.Users
            .Where(u => u.Id == userId)
            .Select(u => new UserModel
                Id = u.Id,
                Name = u.Name,
                Email = u.Email
                // map other user properties as needed

I need to edit data on table by edit every cell on rows 

@if (Users != null && Users.Count > 0)
    <table class="table">
                <!-- add other user property headers as needed -->
            @foreach (var user in Users)
          <button class="btn btn-primary edit-btn" data-id="@user.Id">Edit</button>

so How to allow edit cell   by enabled for edit then close it after edit 

this is image for what i need to do

Answers (2)