Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sending always a null string parameter in RedirectToAction

I have a method to read content of a file like below:

        [HttpPost]
    [ActionName(nameof(ReadFile))]

    public ActionResult ReadFile(FileContentViewModel obj)
    {

        FileStream fileStream = new FileStream(obj.FilePath, FileMode.Open);
        string fileContent ;
        using (StreamReader reader = new StreamReader(fileStream))
        {
            fileContent = reader.ReadLine();
        }

        return RedirectToAction("FileReader", "File", fileContent);


    }

and at the end of the method I want to pass fileContent to below method

  public ActionResult FileReader(string fileContent)
    {


        return View(new FileContentViewModel() { FileContent=fileContent});
    }

Although fileStream has value in first method, but it is always sent with value null once I redirect to the second method.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to redirect with parameter, you can use:

return RedirectToAction("FileReader", "File", new { fileContent= fileContent});

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading