Hi riyab,
Refer the below code and check.
public FileStreamResult CreateFile(string text) {
var byteArray = Encoding.ASCII.GetBytes(text);
var stream = new MemoryStream(byteArray);
return File(stream, "text/plain", "Test.txt");
}
Then you can create an ActionLink to that action on your View which will trigger file download.
@Html.ActionLink("Download File", "CreateFile", "SomeController ")
Or
public ActionResult Download(string text)
{
byte[] data = Encoding.UTF8.GetBytes(text);
return File(data, "text/plain", "Test.txt");
}
In your view provide a link to this action.
@Html.ActionLink("Downoad File", "Download")