0

I have a controller which processes an uploaded file. In that controller, I return the user to a SharePoint list depending on the successful parsing of that file. I am able to enter a direct URL, but I am opening this page in a form so I need to change the window.top.location instead of just window.location. I tried doing this a few ways such as returning a JavaScript result, but I received some browser warning messages I'd like to avoid.

I ended up making a partial razor view which grabs a parameter from the query string in order to determine which list it should go to. The function works fine, but the page is seemingly inactive when I return it using:

return Redirect("~/Parsing/ParsingRedirector?List=MasterDealer");

My page exists in the folder, but I get an error stating "The resource cannot be found. " Any reason why that's happening? I admittedly don't have a full understanding of MVC or even close to it at this point.

2 Answers2

4

Try this:

return RedirectToAction("ParsingRedirector", "Parsing", new { List = "MasterDealer"});
Rosdi Kasim
  • 24,267
  • 23
  • 130
  • 154
  • This actually produced the same result as above. My issue was related to a misnamed view. However, I'm wondering if your approach is a better route to take for the line I added or if it shouldn't matter? –  Jul 26 '15 at 20:21
  • RedirectToAction is type safe. The compiler can catch the error during compilation instead of runtime. Lets say you somehow renamed the `Parsing` Controller to something else, with `RedirectToAction` the code will not compile, you can immediately fix it. – Rosdi Kasim Jul 27 '15 at 03:16
  • Hi @user3362735, Sorry I am wrong on the above comment. I have Resharper in my Visual Studio and it is Resharper catching the error not Visual Studio. For the correct answer to your question, refer to this: http://stackoverflow.com/questions/12198909/what-is-the-difference-between-redirect-and-redirecttoaction-in-asp-net-mvc – Rosdi Kasim Jul 27 '15 at 04:22
0

This may be of help: http://www.dotnet-tricks.com/Tutorial/mvc/4XDc110313-return-View()-vs-return-RedirectToAction()-vs-return-Redirect()-vs-return-RedirectToRoute().html

Keep in mind that, per that article, in the case of Redirect "you have to specify the full URL to redirect."

CindyLu
  • 13
  • 6