C#C
C#4mo ago
MR.ZeRo

✅ Help,web chat, i’m stuck

Hi, so i want to create a simple web chat(using mvc) , and i did, i wanted to make more progress and create users like login and stuff, btw i put sqlite as database so when i want to save the messages into the database i have to change this
public class ChatHub : Hub 
    {
        private readonly ChatContext _context;
        public ChatHub(ChatContext context)
        {
            _context = context;
        }
        public async Task SendMessage(string user, string message)
        {
              var messageEntity = new Message
                {
                    UserId = 1, // Replace with actual user ID
                  Content = message,
                    Timestamp = DateTime.UtcNow
                };
                _context.Messages.Add(messageEntity);
                await _context.SaveChangesAsync();
            
            await Clients.All.SendAsync("ReceiveMessage", user, message);
           
        }

And create context and stuff but when i run the application and want to send a message the message won’t send and gives me error in browser this:.error(err.toString());});
In my chat.js

Anyway here’s my git: https://github.com/Spaceismyhome/SignalRchatAppMCV
GitHub
this is from the Microsoft stuff, but it's under work, so i can make it a proper chat app, and for actual apps - Spaceismyhome/SignalRchatAppMCV
Was this page helpful?