1

I want to redirect to other Umbraco page with model data.

Currently i am just redirecting to other Umbraco page but not with model data.

 public ActionResult CNOReplacement(MasterViewModel Model)
        {
            ViewBag.TestData = "Testing ViewBag data passing !!";
            return RedirectToUmbracoPage(1098);   
        }

Even i have tried by passing viewmodel but that is also not working.

Rahul
  • 2,309
  • 6
  • 33
  • 60

2 Answers2

1

I did not get any solution but have done this using an alternate way,

I have used HttpContext Session Variable to Get Data on Each Umbraco Page.

In controller Action I have created one session

Session["MasterViewModel"]=new MasterViewModel();

And when redirecting to other Umbraco page using below code:

public ActionResult CNOReplacement(MasterViewModel Model)
        {
            return RedirectToUmbracoPage(1098);   
        }

And in View we are getting Session Variable as::

@inherits Proj.ViewModel.MasterViewModel
@{var PerviousPageModel= Session["MasterViewModel"] as MasterViewModel}
Rahul
  • 2,309
  • 6
  • 33
  • 60
  • Spent two days trying make this exact scenario work in Umbraco 7.6.3. I finally came to this exact same solution on my own. The only reason I came accross this is because of a google search trying to figure out if there was a best practice for this scenario. IMHO, this is it! Just make sure to delete the session variable when no longer needed. – Brett Spencer Mar 30 '18 at 16:31
0

[HttpGet]
public ActionResult AAA()
{
GameModel model = new GameModel() { Id = 10 };
return RedirectToAction("BBB", "Game", model);
}

public ActionResult BBB(GameModel model)
{
return View();
}
enter image description here>

Narek Arzumanyan
  • 616
  • 3
  • 11
  • I want to redirect to Umbraco page so that i can use its umbraco templates and Macros. – Rahul Jan 27 '16 at 08:01
  • Use get parameters as public ActionResult method(string param1, int param2,...). And call domain/contollerName/ActionName?param1=value1&param2=value2&... – Narek Arzumanyan Jan 27 '16 at 08:24
  • @Narek, this is an anti-pattern and frowned upon in Umbraco. Besides, it doesn't work when you include the base of RenderModel in your model - as you should. – Brett Spencer Mar 30 '18 at 16:32