小编典典

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

c#

我需要从控制器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();
    }

阅读 1079

收藏
2020-05-19

共1个答案

小编典典

控制器只是类-新的类并像调用其他任何类成员一样调用action方法:

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

2020-05-19