user2156088 user2156088 - 4 months ago 35
C# Question

How to call another controller Action From a controller in Mvc

I need to call a controller B action FileUploadMsgView from Controller A and need to pass a parameter for it.

Code---its not going to the controller B's FileUploadMsgView().
In ControllerA
private void Test()

{//some codes here
ViewBag.FileUploadMsg = "File uploaded successfully.";
ViewBag.FileUploadFlag = "2";

RedirectToAction("B", "FileUploadMsgView", new { FileUploadMsg = "File uploaded successfully" });

In ControllerB receiving part
public ActionResult FileUploadMsgView(string FileUploadMsg)
return View();


Controllers are just classes - new one up and call the action method just like you would any other class member:

var result = new ControllerB().FileUploadMsgView("some string");