Luke Vanzweden
Luke Vanzweden

Reputation: 646

How to update view off model in ASP.NET MVC?

I have a method in my model that finds cameras on the network. The cameras are discovered one by one, and stored in a list named List Cameras. When a new camera is added or a camera is removed, It is instantly updated in the list variable.

On the view, I have

         @foreach(var Item in Model.Cameras) {
            <tr>
                <td>@Item.Name</td>
                <td>@Item.IP</td>
                <td>@Item.HostName</td>
            </tr>
          }

to show a list of cameras. How do I tell the view to update, (without reloading the page) when a camera is discovered or removed? Is this triggered from the Model or the View?

Upvotes: 0

Views: 93

Answers (1)

Riwen
Riwen

Reputation: 5190

This is beyond the scope of ASP.NET MVC. Once an HTTP response has been sent, you cannot modify it. However, there are a number of ways to achieve real-time functionality, such as server-sent events, long polling or WebSocket.

However, since you're using .NET, the best bet would probably be SignalR. SignalR is a real-time library that lets you send "notifications" from your server to any JS (or .NET) clients. Since you haven't specified the version of ASP.NET you're using, I cannot give you one direct link, but take a look at these:

Upvotes: 2

Related Questions