Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to access the TempData key/value from HttpContext?

I'm trying to crate a custom action filter attribute. And some where, I need facilities, such us TempData[key] and TryUpdateModel... My custom attribute class deriving from the ActionFilterAttribute, I can access both below methods.

public override void OnActionExecuting(ActionExecutingContext filterContext) { } public override void OnResultExecuted(ResultExecutedContext filterContext) { } 

Unfortunately, from both filtercontext local variables, I don't know how to access the TempData. I've tried to follow several leads, but without success. After all, maybe there's TempData in the filterContext variables. In that case, how do I access the TemData available?

Thanks for helping

like image 661
Richard77 Avatar asked Nov 23 '10 09:11

Richard77


People also ask

Can we pass TempData from controller to view?

TempData is used to transfer data from view to controller, controller to view, or from one action method to another action method of the same or a different controller. TempData stores the data temporarily and automatically removes it after retrieving a value. TempData is a property in the ControllerBase class.

Can we access TempData in JavaScript?

TempData is created on Server Side of the Web application and hence it is not possible to directly set it on Client Side using JavaScript or jQuery. Thus, only possible way is to set it by making an AJAX call to the Controller's Action method using jQuery AJAX function in ASP.Net MVC Razor.

How do I show TempData values in view?

Passing the data from Controller to View using TempDataGo to File then New and select “Project” option. Then create the ASP.NET web application project as depicted below. Then select “Empty” and tick “MVC” then click OK.

Is TempData a key value pair?

TempData is a dictionary object derived from TempDataDictionary, which can contain key-value pairs, useful for transferring data from controller to view in ASP.NET MVC Application, TempData stays for a subsequent HTTP Request as opposed to other options ( ViewBag and Viewdata ) those stay only for current request.


1 Answers

var foo = filterContext.Controller.TempData["foo"]; 
like image 175
Darin Dimitrov Avatar answered Sep 20 '22 19:09

Darin Dimitrov