2
  • In My main controller to switch views I just call another Action from my controller, but my model I am passing is null after being passed, and is not null beforehand.

    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 pass 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'd receive them in the other Action like so

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

I've been looking for couple hours now only came across This Question that doesn't have a specific answer yet either.

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

Community
  • 1
  • 1
Don Thomas Boyle
  • 3,055
  • 3
  • 32
  • 54

1 Answers1

4

you are not passing "ViewModelViewImages" , instead you are passing new { passedModel = model } just pass the model and you should be fine .

public ActionResult Index(ViewModelViewImages model)
{
    return RedirectToAction("ViewImages",   model  );
}
sino
  • 754
  • 1
  • 7
  • 22