Getting a HTML.ActionLink to work for a partial view
In my view, I have a partial view that pulls in a list of posts. On the sidebar, there is a list of categories that, when a user clicks on, re-generates the partial view but filtered by category type (pass via query string in the HTML.ActionLink). The category type, in Umbraco, is a custom drop-down list that the editor is to select from for each post (limited to one category). The problem is that the test link generates the following error: "There is no current PublishedContentRequest, it must be initialized before the RenderRouteHandler executes".
What is the best way to go about this, to get this id back to the controller for the query within the partial view?
You can't use a Surface Controller in the ActionLink because the controller needs that Context it's complaining about. Surface Controllers are good to post forms or render partial views, but if you click in that link that ActionLink generates you are 'getting out' of the normal Umbraco workflow.
To work around that you can refresh the page (so you use the Umbraco workflow) but sending your category in the request. If there's not category then render all the news (or whatever), if there is then render the right category.
You link would become:
<a href=".?cat=currentevents">Testing</a>
And the call to your controller:
@{
var cat = Request["cat"] ?? null;
Html.RenderAction("RenderListOfArticles", "News", new { category = cat });
}
Thank you, thank you - I tried your approach and it seems to work perfectly!
If you could, can you elaborate when to use Surface Controllers versus RenderMvc Controllers? Would RenderMvc had worked in this instance? I tried it but got a 'No route in the route table matches the supplied values.' - would there be a suitable workaround for this scenario? Trying to understand how Umbraco works in regards to controllers/routing, this is my biggest weak area.
In both cases you need a page to render, when you try to use the RenderLink as I said before you are getting out of the Umbraco workflow. Same thing will happen with the RenderMvcController.
The RenderMvcController is useful to hijack routes. If you check the docs about it, you can see that to instantiate the controller you need to pass a ContentModel, so you still need a 'master page' to render your content.
Probably someone else can give you a better explanation about this, the documentation is actully pretty good. I'd never use any of those controllers for what you need.
Getting a HTML.ActionLink to work for a partial view
In my view, I have a partial view that pulls in a list of posts. On the sidebar, there is a list of categories that, when a user clicks on, re-generates the partial view but filtered by category type (pass via query string in the HTML.ActionLink). The category type, in Umbraco, is a custom drop-down list that the editor is to select from for each post (limited to one category). The problem is that the test link generates the following error: "There is no current PublishedContentRequest, it must be initialized before the RenderRouteHandler executes".
What is the best way to go about this, to get this id back to the controller for the query within the partial view?
In the view, I have this:
The partial view code is as follows:
and then in the News controller, I have
You can't use a Surface Controller in the ActionLink because the controller needs that Context it's complaining about. Surface Controllers are good to post forms or render partial views, but if you click in that link that ActionLink generates you are 'getting out' of the normal Umbraco workflow.
To work around that you can refresh the page (so you use the Umbraco workflow) but sending your category in the request. If there's not category then render all the news (or whatever), if there is then render the right category.
You link would become:
And the call to your controller:
Thank you, thank you - I tried your approach and it seems to work perfectly!
If you could, can you elaborate when to use Surface Controllers versus RenderMvc Controllers? Would RenderMvc had worked in this instance? I tried it but got a 'No route in the route table matches the supplied values.' - would there be a suitable workaround for this scenario? Trying to understand how Umbraco works in regards to controllers/routing, this is my biggest weak area.
In both cases you need a page to render, when you try to use the RenderLink as I said before you are getting out of the Umbraco workflow. Same thing will happen with the RenderMvcController.
The RenderMvcController is useful to hijack routes. If you check the docs about it, you can see that to instantiate the controller you need to pass a ContentModel, so you still need a 'master page' to render your content.
Probably someone else can give you a better explanation about this, the documentation is actully pretty good. I'd never use any of those controllers for what you need.
Thanks, much appreciated!
is working on a reply...