How can client send a value to server using SignalR and the server update a model?

Viewed 2626

If I want to update a model/DB using SignalR, how is this achieved? (The other way around, i.e. from Server to Client is explained in many tutorials, but this way?)

So say we have a simple Model

public class User
{
    public int UserID { get; set; }

    public string UserName { get; set; }

}

And the corresponding View has an input field for the name. The hub is something like

public class UserHub : Hub
{
    public void UpdateName(string value)
    {
        // now what?

        Clients.All.updateTheViewIfNecessary(string newValue);

    }
}

Edit How do I update the model, i.e. how do I achieve the same result as in the regular CRUD edit controller

db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
2 Answers
Related