troubleshooting Question

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

Avatar of Stacie
StacieFlag for United States of America asked on
.NET ProgrammingC#
1 Comment1 Solution71 ViewsLast Modified:
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

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros