mardi 1 août 2017

MVC Application Loading Notifications

I am going to be purchasing an MVC theme from WrapBootstrap http://ift.tt/1i4NW7g for a personal project.

There are alot of things that I like about it design wise, but it has brought up a question about the best way to load notifications in the header (really any sort of dynamic data that needs to load into the common Layout view).

I know there are a great number of ways to do this, but I am at the point in my development experience where I am trying to break my bad design habits (hacking things together so they "just work"), and look for elegant solutions where I can.

The things that make the most sense so far is to either:

1) Create a global ActionFilter that will filter all requests and throw a "LayoutViewModel" into the ViewBag, and just use the ViewBag in the _Layout view.

  • I'd rather do something strongly typed, but I don't see a way.
  • This is nice because it is available, does not require my controllers to inherit any functionality from a base class that might be cludgy, or even know that it is happening.

2) Load the page and onLoad, just do an Ajax Calls to the server to load any dynamic data I need.

  • This may have some disadvantages if your layout needs to change based on the data. I dislike with things snap all over the page after loading.

Is there a design pattern or MVC feature that I may be missing top accomplish this?

I may in the future I may implement something liks SignalR(or a simple timed ajax call to look for updates) to get updated data/notifications, but for now I am just looking at the initial page load.

Thank you for any ideas that you may have.

Aucun commentaire:

Enregistrer un commentaire