Xulfee
Xulfee

Reputation: 986

call other method before action call using asp.net mvc 2

I want to call other method or other technique before action call in asp.net mvc 2.

Because I want to set property in variable then to call action in controller.

can any one guide me if possible.

Upvotes: 0

Views: 1070

Answers (3)

frezq
frezq

Reputation: 702

If all you need to do set is set a controller member variable then a quick and clean method is to override the controller's initialize method like so:

protected override void Initialize( RequestContext rc) {
    base.Initialize(rc);
    //Add any variable initialization here
    employeeId = rc.HttpContext.Request.Cookies["userid"]["emp_id"];
}

Upvotes: 0

Paul Creasey
Paul Creasey

Reputation: 28834

You could implement your own controller factory, see here, and do whatever you like with the controller before you return it.

Upvotes: 1

Related Questions