Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Returning to a different view
Message
From
17/03/2014 15:06:39
 
 
General information
Forum:
ASP.NET
Category:
MVC
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01596244
Message ID:
01596695
Views:
46
>>>>Hi Viv, just to clarify, I put
>>>>
>>>>ViewBag.Caller = Request.UrlReferrer; // in the HttpGet method for Edit ?
>>>>input type="hidden" name="caller" value="@ViewBag.Caller" // In the Edit.cshtml ( angle brackets remove for UT )
>>>>
>>>>
>>>>where do I then get access to this to do the Redirect - must be in the HttpPost method I guess ?, thanks for your help
>>>>
>>>>Edit
>>>>Sussed it, added string caller to the HttpPost Edit method, much better way thanks.
>>>
>>>If you're using a form you don't need to specifically add the caller - you could just access it on the server via : Request.Form["caller"]
>>>
>>>Also, if, for example, the View you wanted to return to was on the same controller you could just do:
string s = Request.Form["caller"];
>>>return View(s.Substring(s.LastIndexOf('/') + 1));
thus avoiding the Redirect()
>>
>>Probably don't want to avoid the redirect after posting the edit: http://www.theserverside.com/news/1365146/Redirect-After-Post
>
>I confess to being unsure whether that is relevant in this instance.
>
>http://www.dotnet-tricks.com/Tutorial/mvc/4XDc110313-return-View()-vs-return-RedirectToAction()-vs-return-Redirect()-vs-return-RedirectToRoute().html

He wants to redirect to an Index view from the Edit's post. If he only returns the view:
1) The url still points to the Edit action.
2) A refresh of what is now an Index page (and should be GET request) will repost the edit.
3) The index view probably requires a different model than the edit view he is coming from.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform