Hi, I noticed that you have CommentService.AddCommentAsync(comment);
which method should come from @inject ICommentService CommentService
.
If you put the codes below within the same component, you will have error like screenshot below.
public interface ICommentService
{
Task AddCommentAsync(ImageComment comment);
List<ImageComment> GetComments();
}
public class CommentService : ICommentService
{
private readonly MyContext _context;
public CommentService(MyContext context) => _context = context;
public async Task AddCommentAsync(ImageComment comment)
{
_context.ImageComments.Add(comment);
await _context.SaveChangesAsync();
}
public List<ImageComment> GetComments() => _context.ImageComments.ToList();
}
I think you can change a name for CommentService
like this: @inject ICommentService _commentService
and _commentService.AddCommentAsync(comment);
If the error I shared is different with yours, please share more about the error you are facing.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Tiny Wang