Currently, I'm working with the following approach and It's working fine but I want to remove the use of TempData. What can I do?
//my class
public myClass{
public int id {get;set;}
public string name {get;set;}
public anotherClass another {get;set;}
}
public anotherClass{
public int id2 {get;set;}
public string name2 {get;set;}
}
//my action method
[HttpPost]
public async Task Search(string searchId)
{
var ob=new myClass();
TempData["myClass"] = JsonConvert.SerializeObject(ob);
return RedirectToAction("DataList");
}
[HttpGet]
public IActionResult DataList()
{
var val = TempData.Peek("myClass");
var res = JsonConvert.DeserializeObject(val.ToString());
return View(res);
}
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Arnab MukherjeePosted Jun 1, 2021, 4:08 PM
Zulqadar IdrishiPosted Jun 1, 2021, 10:36 AM
Arnab MukherjeePosted Jun 1, 2021, 10:19 AM