Orchard CMS - How to use themed and httppost attributes together

428 Views Asked by At

I'm working with Orchard 1.7.2 and in my custom module I have a number of controller actions decorated with the [Themed] attribute.

My problem is that when I also decorate any of them with the [HttpPost] attribute the theme stops working when that action is used.

Has anyone come across this before?

1

There are 1 best solutions below

2
On

Sure, you're telling the action that it shouldn't run for get requests, just for post request. An action marked as post is used for ajax request or for sending a form to the server. (As you point is legitimate to do a post request for a page, I deleted that part, but again is not recommendable)

Try to inject a IWorkContextAccessor, RequestContext and a IThemeManager to your constructor, then in your action do something like this:

  contextAccessor.GetContext().CurrentTheme = themeManager.GetRequestTheme(requestContext);

I don't know if that works, but at least you have a start point.