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.
>Solution :
If you want to redirect with parameter, you can use:
return RedirectToAction("FileReader", "File", new { fileContent= fileContent});
