I am using jquery ajax to post some data to server, save data on the server in TempData and then redirect user to different action.
[HttpPost]
public async Task<IActionResult> GetDocument(SearchFiltersModel filters)
{
var model = await _service.GetDocument(filters);
TempData["Detail"] = model;
return Json("document/detail/" + model.DocumentID)
}
[HttpGet]
public IActionResult Detail()
{
// getting error at line below.
/// ArgumentNullException: Value cannot be null. Parameter name: dictionary
var model = TempData["Detail"] as DocumentModel;
return View(model);
}
$('btn').click(function(){
$.ajax({
type: 'POST',
data: filters,
url: 'document/getdocument'
})
.done(function (response) {
window.location = response;
})
})
However when Detail
action method gets invoked, TempData["Detail"] is null. Why TempData is lost across action methods.
(There is valid reason im doing ajax post on button click rather than form post, but thats irrelevant here)