The documentation for the RedirectToAction method tells us that it sends a 302 response:
"Returns an HTTP 302 response to the browser, causing the browser to make a GET request for the specified action."
Studying the code in the dll shows that it returns a RedirectToRouteResult object, which causes a redirect, so the documentation is correct:
protected internal virtual RedirectToRouteResult RedirectToAction(string actionName, string controllerName, RouteValueDictionary routeValues) { RouteValueDictionary routeValueDictionaries; if (this.RouteData == null) { routeValueDictionaries = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, null, routeValues, true); } else { routeValueDictionaries = RouteValuesHelpers.MergeRouteValues(actionName, controllerName, this.RouteData.Values, routeValues, true); } return new RedirectToRouteResult(routeValueDictionaries); }
The correct answer to the test question is to use a different view:
public ActionResult FindID(int? id) { if (!id.HasValue) { ViewData["Message"] = "Hello!"; return View("Index"); } ViewData["Message"] = "ID is " + id.ToString(); return View(); }
This will use the Index view instead of the FindID , which is returned by a pointless call to View() .
Guffa Jun 25 2018-11-11T00: 00Z
source share