asp.net-mvcmodel-view-controllerdynamicexpandoobjectredirecttoaction

ASP .NET MVC Redirecttoaction passing parameters to Index but values are null


Unable to get controller action to pass values to another. The parameters are getting passed correctly but the values remain null. Code: Need to get the selectregister value from Display() and get info based on it. The info is assigned to ViewList expandoobject and passed to Index().

 [HttpGet]
        public ActionResult Index(Expandoobject vl)
        {
            ViewList = vl;
            if (((IDictionary<String, object>)ViewList).ContainsKey("Applist"))
            {
                ViewList.chk = "Yes";
            }
            else
            {
                getbasics(ViewList);
            }
            ViewList.RegList = GetAllregList(A, B);
            return View("Index", ViewList); //default view
        }
 [HttpPost]
        public ActionResult Display(string selectRegister)
        {
            ViewList.reg = selectRegister;
            ViewList.Applist = ReadAPIinfo(A, selectRegister);
            return RedirectToAction("Index", ViewList);
        }

In the above code, the parameters ViewList.reg, ViewList.Applist are getting passed as null value via ExpandoObject vl. In order to bypass this I'm currently storing the required values in session variables and resolving in a roundabout method. Would like to understand how param passing works (for dynamic expandoobject) in MVC.TIA!! Note: I have used the TempData[] solution suggested in some of the other similar threads but doesn't work with my ExpandoObject variable.


Solution

  • since both actions are in the same controller the easiest way is

    public ActionResult Display(string selectRegister)
            {
              .....
                return Index( ViewList);
            }