简体   繁体   中英

Passing Model through RedirectAction is null

  • 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?

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  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM