I have a form in a view and I pass some information to the Controller through a Submit button. In the controller, in an ActionResult called SaveP I want to verify some conditions and to pass the result of these validations back to the view, so that it display something when the page is reloaded after pressing the submit button.
The code is something like that:
if (!(editor.ID != null && !string.IsNullOrEmpty(editor.Number) && (!ext.SID.HasValue)))
{
_db.M.DeleteM(editor.PID);
pa.P.MID = null;
TempData["m"] = false;
I want the view to display some things only if these conditions apply.
Also, this action result called SaveP redirects to return RedirectToAction("P", new { id = editor.ID });
I have used ViewBag and it didn't work, but then I found out that ViewBag elements don't preserve after a redirect. Then, I tried with a TempData, but it is null in the view. How should I solve this? thanks!
TempDatavalue in the GET method you redirect to? You need to show the relevant code. But if all you want to do is pass aboolvalue then just add a parameter to your method and useRedirectToAction("P", new { id = editor.ID, myBool = false })- user3559349TempDataonly persists between controller actions (eg redirects) and you can only access them once. The action, you redirect to, can add the value of yourTempDatato theViewBag. - Silvermind