I have the following case:
@model MvcApp.Models.MyAppModel
@{ ViewBag.ActionName = this.Context.Request.RequestContext.RouteData.Values["action"]; }
using the debugger i checked and i am certain that Viewbag.ActionName recieves its value.
However in the controller ViewBag is always empty. WHY? i am using this between these requests only ( meaning that i always respect this order, from this view i click an actionlink that always takes me to delete. Please enlighten me. Cheers.
[HttpGet]
public ActionResult Delete(int id)
{
string actionName = ViewBag.ActionName;
any details you need just ask.
The data in the view bag is only valid for the duration of a single request. But your talking about two requests: the first one renders the page and the second one processes the Delete action. That’s why the view bag is initially empty in the controller.