Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a controller named clientjobdescriptionscontroller.cs.

C#
//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));
            }
        }
    }


again I have another controller named RequestController. The methods from this controller is getting called in the first controller.

C#
// 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);
    }


What I have tried:

I have tried to pass the response as parameter but i throws error.
Posted
Updated 5-Apr-16 0:24am
v2
Comments
F-ES Sitecore 4-Apr-16 5:49am    
What does CreatePdf do? What is its return type?
Rakesh Kohale 4-Apr-16 5:53am    
It will create pdf file.


I have tried the same for same controller and its working over there. But When I want to call the same method from another controller then the error comes.
John C Rayan 4-Apr-16 5:56am    
What error are you getting? Which line?
Rakesh Kohale 4-Apr-16 6:01am    
I am getting Response as null in the second controller where The called function is getting called.
Rakesh Kohale 4-Apr-16 5:58am    
I am getting Response as null in the second controller where The called function.

This is because when postback occurs in MVC then the empty page comes so you have to first save your data in TempData and use that TempData in another controller.
Tempdata is used to transfer data from one controller to another.
 
Share this answer
 
you can use TempData: Something like this

controller1:
TempData["abc"] = "write your message here";
controller2:
if(TempData["abc"] !=null)
{
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900