-1

I have a Partial View and fill my TempData with this code block. serviceResponsecont is a list.

TempData["partialResponseList"] = serviceResponseCont;

After this from the PartialView I call the same controller and try to get same data like this.

serviceResponseCont = TempData["partialResponseList"] as List<CadetTest.Controllers.HomeController.cont>;

But it returns me null in second post. I have to carry this list but tempdata didn't help in this way. How can I fix it or is there any solution for this?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • Do you use it twice?you can tempdata of view to controller? – abolfazl sadeghi May 05 '23 at 17:00
  • When I put a list from view in my tempdata i cant pass it to controller @abolfazlsadeghi – Mert Çakar May 05 '23 at 17:29
  • This is a XY problem: you are asking us to help you fix your solution to a problem. However it is not the correct Stilton, so we cannot fix it. Instead explain us what you are trying to do. – JHBonarius May 05 '23 at 20:18
  • Please don't answer my comment in somebody else's answer. Like I said, you using tempdata to achieve your goal is not correct. We can't help you fix that, as that will never work. We need to know why you want you use tempdata, i.e. what data you want to send back. Maybe give a [mcve]. – JHBonarius May 06 '23 at 06:21
  • And let's take a step further back: welcome to stack overflow! Please take the [tour] to see how this site works and check out [help]. Especially look at [ask], regarding what a question should contain in order for us to be able to help you. Finally, if you have additional information to the question, please [edit] it. – JHBonarius May 06 '23 at 06:23
  • possible duplicate: [link](https://stackoverflow.com/q/66241979/6717178) – JHBonarius May 06 '23 at 10:47
  • can you check the link @JHBonarius for more detail.https://stackoverflow.com/questions/76188395/sending-a-list-in-tempdata-from-view-to-controller-net-core – Mert Çakar May 06 '23 at 11:19

2 Answers2

0

TempData is used to store the temporary data

TempData itself cannot be used to send data from View to Controller

TempData is also used for transferring Models/Controllers data to views and other actions/Controllers

There are other ways to transfer Tempdata from view to control

Example

Example3 ExampleWithJquery

abolfazl sadeghi
  • 2,277
  • 2
  • 12
  • 20
0

ASP.net razor views and razor pages are only a template for the html renderer. That means that the code in the razor syntax will all be converted to html. It will not reach the client.

If you want to see that yourself, just take a look at the browser's development tools and look in the network tab on what the client recieved from the server: there is no TempData in there.

I.e. although it's possible to modify the values of C# variables like TempData wiring the razor syntax, it's still only used during html generation before it is send to the client.

If you want the client to send data back to the server, you need another mechanism like html forms.

Since you are not giving details on what you want to send back and when, we can't give an example based on your situation.

JHBonarius
  • 10,824
  • 3
  • 22
  • 41
  • can you please check this link. I explained it with more detail. https://stackoverflow.com/questions/76188395/sending-a-list-in-tempdata-from-view-to-controller-net-core – Mert Çakar May 06 '23 at 11:18