How to resolve the declation of TempData[""] in a static field?

Why can''t I use a TempData within a static method?

I'm getting the following error on this line of code :   empData["ss"] = resultsContainer

C# An object reference is required for the non-static field, method, or property


      public static XtraReport BuildReportObject(DailyEmployeeRecapSearchCriteria searchCriteria
            , Models.Employee LoggedInUser
            , System.Globalization.CultureInfo systemCultureInfo
            , ref XtraReport mainReport
            )
        {
            var resultsContainer = xxx.CustomReports.DailyEmployeeRecapService.GetReportResults(searchCriteria, LoggedInUser.CultureInfo, LoggedInUser.ID.Trim());
            resultsContainer.CustomerDetails.Select(s => s.CustomerNumberAndName = s.CustomerNumber.ToString().Trim() + " - " + (s.CustomerFirstNameLastNameOrCompany ?? "").Trim()).ToList();
            resultsContainer.CustomerDetails.Select(s => s.CustomerNumberAndName += (s.NewCustomer ? " - " + Tools.Language.Translate(Language.Keys.New, LoggedInUser.CultureInfo) + "!" : "")).ToList();

            empData["ss"] = resultsContainer

Open in new window

yguyon28Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi yguyon28;
 
From Microsoft documentation:
A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.

So empData must be sent in as a parameter to use it.

Fernando

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.