如何将Response从一个控制器传递到另一个控制器?

时间:2016-04-04 09:05:34

标签: asp.net-mvc model-view-controller httpresponse

// clientjobdescriptionscontroller.cs

[HttpGet]
        public void Download(string format, string requests)
        {
            List<string> req = requests.Split(',').ToList();
            foreach (var item in req)
            {
                RequestController controller = new RequestController();
                if (format == "I")
                {
                    Response.Write("rakesh");
                    controller.DownloadrequirementsInternalUse(Convert.ToInt64(item));
                }
                if (format == "R")
                {
                    controller.DownloadrequirementsRecruitmentPartner(Convert.ToInt64(item));
                }
                if (format == "CA")
                {
                    controller.DownloadrequirementsCandidate(Convert.ToInt64(item));
                }
                if (format == "CR")
                {
                    controller.Downloadrequirementscustomer(Convert.ToInt64(item));
                }
            }
        }

// RequestController

 public void DownloadrequirementsInternalUse(long Id)
        {
            var result = requestService.GetResourceAvailability(Id);

            JobDescriptionPdfDownload jobDescriptionPdfDownload = new JobDescriptionPdfDownload();
            string strOutput = jobDescriptionPdfDownload.DownloadrequirementsInternalUse(Id);

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=JD-Internal-Use-" + result.RequestCode + ".pdf");

            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            CreatePdf(strOutput);
        }

2 个答案:

答案 0 :(得分:0)

Use your action method like this

public ActionResult Download(string format, string requests)
{

}

答案 1 :(得分:0)

尝试在控制器中使用action方法(return actionresult)并尝试使用

return RedirectToAction("DownloadrequirementsInternalUse", "RequestController", new {  id=Convert.ToInt64(item) });