Not sure if this is possible, but I am trying to perform a redirection from within a View Component. From Google searches, I understand it would be better to do the redirect from the razor page, however in this case, it is not as straightforward.
I can perform the redirect by injecting IHttpContextAccessor, in the View Component, and calling
to redirect to the required page. However when I do this, Umbraco appears to process the View Component cshtml file anyway, and since a model is not being passed to the View, I am having to wrap all Razor code which accesses the Model in an if statement which checks the Model is not null.
Redirect from a ViewComponent
Hi All,
Not sure if this is possible, but I am trying to perform a redirection from within a View Component. From Google searches, I understand it would be better to do the redirect from the razor page, however in this case, it is not as straightforward.
I can perform the redirect by injecting IHttpContextAccessor, in the View Component, and calling
to redirect to the required page. However when I do this, Umbraco appears to process the View Component cshtml file anyway, and since a model is not being passed to the View, I am having to wrap all Razor code which accesses the Model in an if statement which checks the Model is not null.
Is there a better way to do this?
Thanks
Kap.
I can use a flag in the model to indicate that we should abort the processing of the razor code
eg:
Not sure if it is the most elegant solution, but appears to work.
is working on a reply...