Passing a model through RedirectAction is zero

  • In my main controller, to switch views, I just call another action from my controller, but my model that I pass is null after it is passed and has no null value.

    public ActionResult Index(ViewModelViewImages model) { return RedirectToAction("ViewImages", new { passedModel = model }); } 
  • In the same controller ..

     public ActionResult ViewImages(ViewModelViewImages passedModel) { //passedModel.(WhateverMyAttributesAre) = null every time } 

  • However, I can write out my variables and they go just fine

      string pro = model.Prospects; string cnt = model.Countys; string twn = model.TownShips; string rng = model.Ranges; string sct = model.Sections; return RedirectToAction("ViewImages", new { idpro = pro , idcnt = cnt, idtwn = twn, idrng = rng, idsct = sct}); 
  • In return, I would get them in another action like this:

      public ActionResult ViewImages(string idpro, string idcnt, string idtwn, string idrng, string idsct) 

I searched for a couple of hours, just stumbled upon This question , which does not yet have a specific answer.

Is there a good reason for this? / What am I doing wrong?

+1
source share
1 answer

you do not pass " ViewModelViewImages ", instead you pass new { passedModel = model } just pass the model and everything will be fine.

 public ActionResult Index(ViewModelViewImages model) { return RedirectToAction("ViewImages", model ); } 
+2
source

All Articles