Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:03:22+00:00 2026-06-05T02:03:22+00:00

I’m trying to build a notifications provider (alerts) for my application. Currently I only

  • 0

I’m trying to build a notifications provider (alerts) for my application. Currently I only need to generate notifications between requests, but having this functionality wrapped in a provider will allow me to hook it up to the database later.

I have 3 types of notifications:

public enum NotificationType
{
    Success,
    Error,
    Info
}

and a Notification object:

public class Notification
{
    public NotificationType Type { get; set; }
    public string Message { get; set; }
}

I would like to put all notifications in List<Notification> and load it into ViewData["Notifications"]

I could then use the helper to read ViewData["Notifications"] and render it:

I want to implement my own NotificationProvider which would maintain the List<Notification> object.

I want the provider to read TempData[“Notifications”] and load it into List<Notification> Notifications variable. I could then load notifications into ViewData[“Notifications”] for my helper to use.

Code below isn’t working but I think it shows what I’m trying to do.

public class NotificationProvider
{
    public List<Notification> Notifications { get; set; }

    private Controller _controller;

    public NotificationProvider(Controller controller /* How to pass controller instance? */)
    {
        _controller = controller;

        if (_controller.TempData["Notifications"] != null)
        {
            Notifications = (List<Notification>)controller.TempData["Notifications"];

            _controller.TempData["Notifications"] = null;
        }
    }

    public void ShowNotification(NotificationType notificationType, string message)
    {
        Notification notification = new Notification();

        notification.Type = notificationType;
        notification.Message = message;

        Notifications.Add(notification);

        _controller.TempData["Notifications"] = Notifications;
    }

    public void LoadNotifications()
    {
        _controller.ViewData["Notifications"] = Notifications;
    }
}

And in each controller a NotificationProvider instance:

public class HomeController
{
    private NotificationProvider notificationProvider;

    public HomeController()
    {
        notificationProvider = new NotificationProvider(/* Controller instance */);
        notificationProvider.LoadNotifications();
    }
}

Question:

How do I pass the controller instance to NotificationProvider class so it can access TempData and ViewData objects. Or if it’s possible, how can I access those objects directly from NotificationProvider instance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:03:23+00:00Added an answer on June 5, 2026 at 2:03 am

    I think you only want to pass this, like that. Also, back from comments, TempData will only be available in actions:

    public class HomeController
    {
        public ActionResult Index()
        {
            var notificationProvider = new NotificationProvider(this);
            notificationProvider.LoadNotifications();
            return View();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.