I have a method (MethodA) in my controller that needs to return another ActionResult
(methodB) in that same controller, with some parameters as payload. For this I use a RedirectToAction(nameof(methodB), new { param1=param1, param2=param2 } )
at the end of MethodA.
When I debug, all the parameters are loaded and contain the expected values. However when it arrives at methodB, the two parameters are empty.
MethodA
[HttpPost]
public ActionResult Bulkimport(int id)
{
int customerId = 5;
ReturnModel returnMessage = new ReturnModel();
returnMessage.Message= "All data loaded";
returnMessage.returnModel = returnModel; //contains list with some data
return RedirectToAction(nameof(Bulkimport), new { id = customerId, model = returnMessage });
}
MethodB
[HttpGet]
public ActionResult Bulkimport(int id, MessageModel model)
{
// Do stuff, but MessageModel and id are null.
return View();
}
Does anyone have an idea what might be happening here? Additional: I have some experiences that additional parameters are presented in the receiving view as a querystring in the url in the browser. Is there any way to prevent it?
Thanks
Change:
return RedirectToAction(nameof(Bulkimport), new { id = customerId, model = returnMessage });
To
return Bulkimport( customerId, returnMessage);
````
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.