# How to access RequestModel while using a custom controller (site.axd)?

**URL:** <https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668>\
**Category:** Questions\
**Tags:** accelerator, litium-7\
**Created:** [March 6, 2019, 10:39am UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668 "2019-03-06T10:39:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hans](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/hans/32/31_2.png) [@hans](https://forum.litium.com/u/hans)\
**Post date:** [March 6, 2019, 10:39am UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/1 "2019-03-06T10:39:33Z")

</div>

Using a “custom controller” accessed through the site.axd route the `Litium.Accelerator.Mvc.Routing.RequestModelHandler.AccessorCleanup.Dispose()` method is called before `Litium.Accelerator.Mvc.Routing.RequestModelActionFilter.OnActionExecuting()` is called which means that `RouteRequestLookupInfoAccessor.RouteRequestLookupInfo` is null and we don’t get the RequestModel.

What are we doing wrong?

Litium version: 7.1

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [March 6, 2019, 2:20pm UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/2 "2019-03-06T14:20:04Z")

</div>

`Litium.Accelerator.Mvc.Routing.RequestModelHandler` is used for api controllers request and will only be used if the `litium-request-context` http header is included with the request.

`Litium.Accelerator.Mvc.Routing.RequestModelActionFilter` is used for mvc controllers.

If you get the `Litium.Accelerator.Mvc.Routing.RequestModelHandler.AccessorCleanup.Dispose()` to be executed when you executing an mvc controller you are passing in the `litium-request-context` http header with the request that will make both of them to execute.

If you need to pass the request context into the mvc controller you should probably change to use another name of the http header to not get conflicts between them.

---

<div class="post-metadata">

**Author:** ![emilsjog](https://avatars.discourse-cdn.com/v4/letter/e/ec9cab/32.png) [@emilsjog](https://forum.litium.com/u/emilsjog)\
**Post date:** [April 1, 2019, 3:02pm UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/3 "2019-04-01T15:02:56Z")

</div>

How do I avoid the Dispose() to run before the action? I’m also trying to call an custom mvc-method. Shouldn’t I use the `litium-request-context` header?

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 1, 2019, 3:27pm UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/4 "2019-04-01T15:27:48Z")

</div>

I think the problem you are getting is that you returning an `IEnumerable<>` that is only a placeholder and not populated before later when it is used; after the `Dispose` have been executed. Instead you should return an `IList<>` or other populated object from the controller

---

<div class="post-metadata">

**Author:** ![emilsjog](https://avatars.discourse-cdn.com/v4/letter/e/ec9cab/32.png) [@emilsjog](https://forum.litium.com/u/emilsjog)\
**Post date:** [April 1, 2019, 4:21pm UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/5 "2019-04-01T16:21:58Z")

</div>

I’m returning a `ActionResult` and a `CategoryPageViewModel` as `View(model)`. Is there any difference if the method is GET or POST? I’m using POST to my method now.

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 2, 2019, 5:13am UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/6 "2019-04-02T05:13:44Z")

</div>

> [@emilsjog](#):
>
> I’m returning a `ActionResult` and a `CategoryPageViewModel` as `View(model)` .

What properties do you have on your `model` ?

> [@emilsjog](#):
>
> Is there any difference if the method is GET or POST? I’m using POST to my method now.

GET and POST should behave the same.

---

<div class="post-metadata">

**Author:** ![emilsjog](https://avatars.discourse-cdn.com/v4/letter/e/ec9cab/32.png) [@emilsjog](https://forum.litium.com/u/emilsjog)\
**Post date:** [April 2, 2019, 6:09am UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/7 "2019-04-02T06:09:06Z")

</div>

The properties are the same as in vanilla accelerator.

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 2, 2019, 7:05am UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/8 "2019-04-02T07:05:38Z")

</div>

> [@patric.forsgard](#):
>
> If you get the `Litium.Accelerator.Mvc.Routing.RequestModelHandler.AccessorCleanup.Dispose()` to be executed when you executing an mvc controller you are passing in the `litium-request-context` http header with the request that will make both of them to execute.

This model is used for the web-api endpoints. If you want to build the same to use for an mvc controller you need to change the name and replicate the logic in an action filter, like the `Litium.Accelerator.Mvc.Routing.RequestModelActionFilter` but reading the data from the header instead.

---

<div class="post-metadata">

**Author:** ![emilsjog](https://avatars.discourse-cdn.com/v4/letter/e/ec9cab/32.png) [@emilsjog](https://forum.litium.com/u/emilsjog)\
**Post date:** [April 2, 2019, 8:12am UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/9 "2019-04-02T08:12:20Z")

</div>

The model is used in the Index method on the CategoryController and it’s a mvc controller. And I have made a simple action that is returning a partialView in the same controller. Still my problem is that the dispose gets hit before the method. What is the result of not running the `registerForDispose` on a certain request? I’m thinking of checking if a certain header is present and skip the `registerForDispose` then

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 2, 2019, 8:29am UTC](https://forum.litium.com/t/how-to-access-requestmodel-while-using-a-custom-controller-site-axd/668/10 "2019-04-02T08:29:25Z")

</div>

If the object not is disposed as they should they can cause an _memory leak_, this depend on the objects that are used on how garbage collection can handle and clean it up.
