user3155141
user3155141

Reputation: 11

ASP NET MVC partial view rendering without postback request form view to controller?

I am using ASP NET MVC4, I want to use partial view to update my main view. On the server I get certain events from another server, and when that happens I want to update the partial view and post it to the client. How can I do that? In other words, I want a way to force rendering partial view on the server side without a postback request coming from the client. Is that possible, or the client must be informed first and then does its own postback action to trigger the partial view rendering?

Upvotes: 1

Views: 1801

Answers (2)

Nathan Teague
Nathan Teague

Reputation: 875

This is a better job for SignalR for large scale Real-time work reference:

[http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-server][1]

Or if you just need to stay on single medium, you can look into node.js, which is Server side javascript and allows for binding of js function to server driven events (i.e. Client independent)

One last thought would be to use events and kick out Web Api Responses, but that would be getting a lot of weight on JSON without page requests.

Upvotes: 0

Amar Kate
Amar Kate

Reputation: 71

Call The follwing Ajax call on every other server event or call it periodically

$.get('@Url.Action("ActionName", "ControllerName")', function (data) {
                $('#Id of div where Partial View is renderred').html(data);
});

In the action called.

public ActionResult ActionName()
{
         //load your model with changes

         return PartialView("Name of your partial view", model);

}

Upvotes: 1

Related Questions