I need to merge some none Umbraco news content into my Umbraco site. I want to have news page that lists the stories and a sidebar widget that I can add to other pages, which I intended to build as a partial view.
You can also do it without adding an extra route. If you post it to a SurfaceController it will also work. You can also use a SurfaceController for route hijacking so you can have your "public ActionResult News(RenderModel renderModel)" method and "[ChildActionOnly] public ActionResult Widget()" method in the same controller: http://issues.umbraco.org/issue/U4-2342
Old question I know, but this has just helped me out moving from webforms.
Is this simply a limitation of ASP.NET MVC? Because coming from a usercontrols background it seems a bit insane to have to programmatically assign routes on application startup just to include a reusable code snippet.
I know I can create a SurfaceController instead, but one of the great advantages of Umbraco was always that you didn't have to create CMS specific wrappers for every tiny piece of functionality.
I freely admit I am finding MVC in general a total nightmare to get my head round (and the help available on the web to be woeful), so I'm probably just missing some key concepts.
RenderMvcController and partial views
I need to merge some none Umbraco news content into my Umbraco site. I want to have news page that lists the stories and a sidebar widget that I can add to other pages, which I intended to build as a partial view.
I created the following controller....
public class NewsController : Umbraco.Web.Mvc.RenderMvcController
{
public ActionResult News(RenderModel renderModel)
{
...code goes here...
return View(model);
}
[ChildActionOnly]
public ActionResult Widget()
{
...code goes here...
return PartialView(model);
}
}
The news page works fine, but I'm having trouble with the partial view.
In my cshtml files I'm using...
@Html.Action("Widget", "News")
...but I always get "No route in the route table matches the supplied values."
I've been trying to get this to work for most of my Saturday afternoon, so any help is very much appreciated!
I'm quite new to MVC, so apologies if I've made a really stupid mistake :)
Got it working now!
In case anyone with the same problem finds this through Google, I just needed to register the route.
Create a class that inherits IApplicationEventHandler with the following...
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
RouteTable.Routes.MapRoute(
"News",
"News/Widget",
new { controller = "News", action = "Widget" }
);
You can also do it without adding an extra route. If you post it to a SurfaceController it will also work. You can also use a SurfaceController for route hijacking so you can have your "public ActionResult News(RenderModel renderModel)" method and "[ChildActionOnly] public ActionResult Widget()" method in the same controller: http://issues.umbraco.org/issue/U4-2342
Jeroen
Old question I know, but this has just helped me out moving from webforms.
Is this simply a limitation of ASP.NET MVC? Because coming from a usercontrols background it seems a bit insane to have to programmatically assign routes on application startup just to include a reusable code snippet.
I know I can create a SurfaceController instead, but one of the great advantages of Umbraco was always that you didn't have to create CMS specific wrappers for every tiny piece of functionality.
I freely admit I am finding MVC in general a total nightmare to get my head round (and the help available on the web to be woeful), so I'm probably just missing some key concepts.
is working on a reply...