0

I'm getting the "request url too long" error whenever I click on my actionlink. It makes sense since this is a really long string, but I need to pass this string to the controller somehow.

Here's the actionlink from the View:

@Html.ActionLink("Download Error Text File", "GenerateFile", "Home", new { @errorMessage = Model.customersError }, new { @id = "downloadfile" })

It is calling this action result in the controller:

public ActionResult GenerateFile(string errorMessage)
        {
            var byteArray = Encoding.ASCII.GetBytes(errorMessage);
            var stream = new MemoryStream(byteArray);

            return File(stream, "text/plain", "Customer_Errors-" + DateTime.Now.Date.ToString("MM-dd-yyyy") + ".txt");
        }

So this is a link the user would click to download a plain text file with all the errors. Is there an alternative way of passing this value to the controller so it doesn't get put in the url?

Stephanie
  • 1,039
  • 1
  • 7
  • 12
  • See also [When to use TempData vs Session in ASP.Net MVC](http://stackoverflow.com/questions/1500402/when-to-use-tempdata-vs-session-in-asp-net-mvc), [What is the right time for ViewData, ViewBag, Session, TempData](http://stackoverflow.com/questions/12676924/what-is-the-right-time-for-viewdata-viewbag-session-tempdata) and so on. – CodeCaster Jul 09 '15 at 19:24
  • Use HttpPost on your controller method and change the actionlink to an actual form. – Brad C Jul 09 '15 at 19:35
  • not sure why this a duplicate of "Saving state between actions". There are way better answers than saving in Session.. TempData, ViewData, and ViewBag certainly don't apply here – JamieD77 Jul 09 '15 at 19:43
  • @Jamie OP's question is _"How to persist values (namely the error list) between requests"_. This is explained in the three links I gave. If OP has further questions, they can edit and vote to reopen. – CodeCaster Jul 09 '15 at 20:21
  • question is how to get a long string `Model.customersError` from the `View` to an `Action` using `ActionLink` – JamieD77 Jul 09 '15 at 20:22
  • creating a hidden field in a form and using httppost like @br4d mentions is certainly a better option than storing the information in `Session`. none of the links you posted will assist in this case. Maybe you should post a link that advises using the `ErrorID` as a model property and passing it to the Action as a parameter to retrieve the Error message – JamieD77 Jul 09 '15 at 20:30
  • @JamieD77 I don't think I could use an ErrorID for this since Model.customersError is from a viewmodel. It's not stored in the database. – Stephanie Jul 10 '15 at 15:18

0 Answers0