I'm using 7.2.4. In my site I have a page where I want to use a route like this profile/{vanityurl}. In my case, the profiles do not exist as Umbraco content but rather they come from intergration with another system. I have a document type, template and page for the profile. My questions is, how do I allow this page to accept the /{vanityurl} in the route?
And used EnsurePublishedContentRequest on the cotroller action
public class ProfileController : SurfaceController
{
[EnsurePublishedContentRequest(2263)]
public ActionResult ShowProfile(string vanityurl)
{
//todo: do something...
return PartialView("~/Views/Partials/Profile.cshtml");
}
}
However, the view that's rendered isn't using the master template of the page. Instead, just the partial template is rendered.
I've also looked at this article and some other forum posts and they seem geared towards content that actually exists in Umbraco, using UmbracoVirtualNodeRouteHandler to find the child node and associate it with the route. In my case, all I want to do is to be able call the one page with a custom route.
RouteTable.Routes.MapUmbracoRoute(
"profile",
"profile/{vanityurl}",
new
{
controller = "Profile",
action = "ShowProfile"
},
new ProfileRouteHandler(2263));
The route handler:
public class ProfileRouteHandler : UmbracoVirtualNodeByIdRouteHandler
{
public ProfileRouteHandler(int nodeId)
: base(nodeId)
{
}
}
Controler:
public class ProfileController : SurfaceController
{
public ActionResult ShowProfile(RenderModel model, string vanityurl)
{
//todo: do something...
return View("~/Views/Profile.cshtml", model);
}
}
The reason my master template was not being used is because I incorrectly assumed that my controller's action was being called by Umbraco as a child action. When I added the Layout to the view and passed the RenderModel it worked as expected.
Now I'm stuck on another issue. In my view I want to use a model:
public ActionResult ShowProfile(RenderModel model, string vanityurl)
{
RouteData.DataTokens["umbraco"] = model;
var profileModel = new ProfileModel() {FirstName = "test", LastName = "data"};
//todo: do something...
return View("~/Views/Profile.cshtml", profileModel);
}
But it results in a error: The model item passed into the dictionary is of type 'ExternalSite.Models.ProfileModel', but this dictionary requires a model item of type 'Umbraco.Web.Models.RenderModel'.
Any ideas on how I can use a custom model? If I'm going about this the wrong way please let me know.
Yes, I can't remember where I found some documentation but it looks something like this. I just reviewed it to see if I could refresh my memory more but it's been too long.
RouteTable.Routes.MapUmbracoRoute(
"profile",
"profile/{vanityurl}/{zipCode}",
new
{
controller = "Profile",
action = "ShowProfile",
zipCode = UrlParameter.Optional
},
new PageRouteHandler(int.Parse(WebConfigurationManager.AppSettings["ProfilePageId"])));
The view that the controller is returning inherits a class derived from RenderModel.
custom route for regular content
I'm using 7.2.4. In my site I have a page where I want to use a route like this profile/{vanityurl}. In my case, the profiles do not exist as Umbraco content but rather they come from intergration with another system. I have a document type, template and page for the profile. My questions is, how do I allow this page to accept the /{vanityurl} in the route?
I've registered a route for the controller
And used EnsurePublishedContentRequest on the cotroller action
However, the view that's rendered isn't using the master template of the page. Instead, just the partial template is rendered.
I've also looked at this article and some other forum posts and they seem geared towards content that actually exists in Umbraco, using UmbracoVirtualNodeRouteHandler to find the child node and associate it with the route. In my case, all I want to do is to be able call the one page with a custom route.
Any Suggestions?
Thanks,
Ryan
I think I found a solution following this post.
My route:
The route handler:
Controler:
The reason my master template was not being used is because I incorrectly assumed that my controller's action was being called by Umbraco as a child action. When I added the Layout to the view and passed the RenderModel it worked as expected.
Now I'm stuck on another issue. In my view I want to use a model:
I've tried this:
But it results in a error: The model item passed into the dictionary is of type 'ExternalSite.Models.ProfileModel', but this dictionary requires a model item of type 'Umbraco.Web.Models.RenderModel'.
Any ideas on how I can use a custom model? If I'm going about this the wrong way please let me know.
Did you made any progress on this ?
Yes, I can't remember where I found some documentation but it looks something like this. I just reviewed it to see if I could refresh my memory more but it's been too long.
The view that the controller is returning inherits a class derived from RenderModel.
is working on a reply...