如何从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");
以上是 如何从Mvc中的控制器调用另一个控制器操作 的全部内容, 来源链接: utcz.com/qa/431230.html