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

  • SEARCH
  • Home
  • 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 6874813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:14:30+00:00 2026-05-27T04:14:30+00:00

I am attempting to call a controller via an actionLink() in a view. This

  • 0

I am attempting to call a controller via an actionLink() in a view. This controller get’s data from a TempData repository. However, it seems that no matter what I do, if I set the TempData repository in the view, it won’t go over to the controller? Should I use ViewData instead? What is your recommendation for a system such as that?

Thanks

  • 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-05-27T04:14:31+00:00Added an answer on May 27, 2026 at 4:14 am

    TempData, nor ViewData is supposed to be set in a view. A view is supposed to consume data that has been stored in those structures inside your controller actions (well, actually it isn’t, a view is supposed to consume a view model but that’s another topic).

    TempData could be used when you want to persist information between two redirects. It should be set inside a controller action which redirects to another controller action that will read the data:

    public ActionResult Foo()
    {
        SomeModel model = ...
        TempData["foo"] = model;
        return RedirectToAction("Bar");
    }
    
    public ActionResult Bar()
    {
        var model = TempData["foo"] as SomeModel;
        ...
    }
    

    So a controller action should get data from the TempData structure only if this action has been invoked after a redirect from another action that set the data. Such controller action should never be invoked from a view because if you have a view this means that this view was rendered from a controller action that presumably set the data into TempData but there is always a risk (if the view performs in between a request to the server – AJAX or something), the TempData will be lost.

    For your case, when a view needs to invoke the server there are basically 3 techniques:

    • Use an HTML <form> with input fields that will send the data to the server
    • Use an anchor and pass data as query string parameters to the controller
    • Use javascript and send an AJAX request or a redirect to the server
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time attempting to call an ASP.NET page method from jQuery.
I'm attempting to do an AJAX call (via JQuery) that will initiate a fairly
Attempting to use the data series from this example no longer passes the JSONLint
I am attempting to call SQL stored procedure that does an INSERT. However, when
Attempting to print out a list of values from 2 different variables that are
I'm attempting to call a method written in C++/CLI from C#. The C++/CLI code
I am attempting to call an ASP.NET page from a classic ASP page on
setup Controller -> Action Index results = Model.all (SQL Call) View Loop through and
I am attempting to call a C++ API from python. Following is the code
I would like to have controller GET action that returns a JSON-serialized dictionary. The

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.