如何从驻留在不同控制器中的另一个操作调用操作

时间:2015-05-01 18:33:01

标签: c# asp.net-mvc-4

我有一个执行某些操作的控制器。现在,我需要在上述控制器的中间发生某些功能(发送电子邮件)。

try
   {
   using (HttpClient client = new HttpClient())
      {
       // Add an Accept header for JSON format
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        response = client.PostAsJsonAsync(URLForReportsapi + "InsertOrUpdatePortal", criteria).Result;
       }
      // Throw exception if not a success code.
        response.EnsureSuccessStatusCode();
      // Parse the response body.
        var pVMRslt = response.Content.ReadAsStringAsync().Result;
        var pVMRsltDsrlz = JsonConvert.DeserializeObject<List<PortalInfoVM>>(pVMRslt);
        portalVMList = pVMRsltDsrlz.ToList();
        var newnumids = portalVMList.Where(c => c.isNewStatus == "NEW").Select(c => c. numid).ToList();
 //-------- Here I need to call another action which is residing inside another controller.
        return PartialView("AddToPortalConfirmation", portalVMList);
   }

在调用partialview之前的上面一段代码中我需要调用另一个驻留在不同控制器内的动作并返回PartialView("AddToPortalConfirmation", portalVMList)

我试图做这样的事情,但这不起作用。

  var resp = RedirectToAction("Create", "EmailReport", new { numids = newnumids , To = toEmail});

在我的routeconfig.cs中我有

  routes.MapRoute(
             null, // Route name
             "EmailReport/Create/{To}/{numids }", // URL with parameters
             new { controller = "EmailReport", action = "Create", To = string.Empty, numids = string.Empty } // Parameter defaults
         );

1 个答案:

答案 0 :(得分:0)

尝试:

return RedirectToAction("Create", "EmailReport", new { numids = newnumids , To = toEmail});