如何从 Mvc 中的控制器调用另一个控制器操作 [英] How to call another controller Action From a controller in Mvc
本文介绍了如何从 Mvc 中的控制器调用另一个控制器操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从控制器 A 调用控制器 B 的操作 FileUploadMsgView 并需要为其传递参数.
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()
{
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 方法:
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");
这篇关于如何从 Mvc 中的控制器调用另一个控制器操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文