Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel 9 posts 79 karma points
    Aug 01, 2016 @ 15:30
    Daniel
    0

    Custom routing - revisited

    Hi,

    I am trying to build a website, which basically doesn't needs Umbraco now (or the functionality it is very small). First of all I need to say that I have read all the forum threads about custom routing, and I know what this is but something it is missing.

    I want to create a view which it is not based on any document type from umbraco. I just want to have a view with a simple POCO object to be able to pass it as a model at the page creation and in the POST.

    Why ? Because on those fields I need to create a PDF document and save it to the database. I know that I can define a Media Type with some fields that could be used and use Umbraco to manage the content too.

    However I have some reasons that I don't want to do that: - the PDF content I don't want to be accesed by anyone else (except the user) - the fields that I define for a PDF, has a logic for creating. For example, field 1 + field 2 makes the Filed 3 to be invalid, and so on.

    If I go with the ideea to create a Media Type, I know that I can use a IContentFinder to fillin the needed RenderModel to be able to process the request, but my question is:

    Can you somehow make Umbraco skip the verification of a RenderModel for a particular request ? I know that that would involve skipping a lot of benefits from Umbraco, but for that particular view I don;t need the Umbraco logic.

  • David Peck 585 posts 1548 karma points c-trib
    Aug 01, 2016 @ 16:52
    David Peck
    0

    If you just want a POCO model then inherit your page from @UmbracoViewPage

    You'll need to create your poco in a custom controller of course.

    I think you'll need at least one page in your site, because even a custom IContentFinder will need to pass an IPublishedContent. You could of course create your own IPublishedContent, but when I tried to do this with an ID that didn't exist then something further up the pipeline got upset.

  • Daniel 9 posts 79 karma points
    Aug 01, 2016 @ 17:58
    Daniel
    0

    So, I have some document types defined in Umbraco but those have sense in other pages, not in my page that I want a POCO.

    In my Ubraco 7.4 the page it is defined like this: public abstract class UmbracoViewPage : UmbracoViewPage

    Like I said, in my particular view, I want to don't have attached any IPublishedContent to it, and i want my model to be typed to a POCO object.

    I could make a hack of course: generate a Dummy Content type, and Inherit my POCO object from that class. However I find it hackish and it would be great if this can be avoided

    I already made my controller and I had multiple attempts: to inherit from SurfaceController, UmbracoController ... anything that could work for frontend.

    I haven't seen any example with my requests, and I start to think that it is imposible to do it.to do that in Umbraco

  • Shannon Deminick 1463 posts 4892 karma points hq
    Aug 03, 2016 @ 08:55
    Shannon Deminick
    0

    I'm not sure if you are fully aware of real custom Umbraco MVC routes? see: https://our.umbraco.org/documentation/reference/routing/custom-routes#custom-routes-within-the-umbraco-pipeline

    ... this is not IContentFinder, this is an MVC route that will execute in the context of Umbraco - for which you need to assign an IPublishedContent instance to render. Articulate does this for all of it's tags/category listing and pages.

    The fact is that MVC requires that a "master view" has the same model as the view being rendered. This is not an issue with Umbraco, this is how ASP.Net MVC works.

    So, if you don't want to be hacky, you need to reconfigure your master view in a different way. Generally speaking, in the MVC world a master view is 'dumb' and doesn't do anything, it doesn't lookup data, it just renders parts of the sub views and partial views. In this case, you could make your master view have a @model dynamic, then it doesn't care what model your views are using.

    But... I assume that your master view is not 'dumb', it probably renders some navigation elements, it probably knows about other Umbraco content to build up it's display. Therefore, it must know about Umbraco and it needs to have an UmbracoContext (i.e. the Context from which to create itself from) which is associated with some IPublishedContent instance. When you perform custom routing within Umbraco - because you know some part of your page needs to know about Umbraco, then you need to use UmbracoVirtualNodeRouteHandler of some sort, this handler could return your root node as IPublishedContent if you wanted, it doesn't matter, but if you master view is rendering Umbraco content, it needs a context.

  • Daniel 9 posts 79 karma points
    Aug 03, 2016 @ 09:36
    Daniel
    0

    Hi Shannon !

    Thanks for your reply. After what you wrote, I made a double check of what I was doing wrong, and it seems that the reason it was this:

    @model DocGen.Umbraco.ViewTransferObjects.CreateDocument @{ Layout = "~/Views/Shared/_Cluster.cshtml"; }

    In my view, I was specifying a layout which that one needs a content of a certain document type. This is needed for rendering the Footer (I have the social network links in a Site document type defined).

    If I set the Layout to null, indeed the error dissapears and I can happy render my page.

    Having this said, how do you think it is the best practice to proceed in this case. I am thinking to the following stuff:

    -to define a IContentFinder and insert it it just before the 404NotFound one

    -this content finder should always set the PCR Site, because this is needed by the Master page

    If I do this, I am able to have a RenderModel, and a initialize a view from a POCO object ?

    Do you think this is enought this ?

  • Daniel 9 posts 79 karma points
    Aug 03, 2016 @ 09:47
    Daniel
    0

    Actually I am wrong.

    The reason the request it was failing, is because the Layout master page it was inheriting from @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    Oh my god, I've stayed a lot of days on this :)

Please Sign in or register to post replies

Write your reply to:

Draft