c# – 如何调用另一个控制器操作从Mvc中的控制器

我需要从控制器A调用控制器B操作FileUploadMsgView,需要为它传递一个参数。

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

        try
        {//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();
    }
最佳答案
控制器只是类 – 新的和调用action方法就像任何其他类成员:

var result = new ControllerB()。FileUploadMsgView(“some string”);

转载注明原文:c# – 如何调用另一个控制器操作从Mvc中的控制器 - 代码日志