Copied to clipboard

Flag this post as spam?

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


  • Mihail 39 posts 142 karma points
    Jun 15, 2016 @ 08:12
    Mihail
    0

    Create a controller for route via template

    Hi,

    I created a document type called Language (alias name is language).

    I created a content called EN and I can access it thorught http://mywebsite/en

    I created a controller:

    public class LanguageController : RenderMvcController
    {
       public override ActionResult Index( RenderModel model )
       {
         Debug.WriteLine( model.CurrentCulture );
          return base.Index( model );
       }
    }
    

    I put breakpoint on line where is Debug.WriteLine and when access the url: http://mywebsite/en

    then that breakpoint is never reached.

    I read this page ( how mapping works ):

    Document Type name = controller name * Template name = action name

    Where is my mistake ?

  • Micha Somers 134 posts 597 karma points
    Jun 15, 2016 @ 13:31
    Micha Somers
    0

    Where did you create the controller?

    In case you created it in a seperate class library, make sure you add a reference to that library in your project.

  • Mihail 39 posts 142 karma points
    Jun 15, 2016 @ 13:35
    Mihail
    0

    I created in same project with umbraco. In MVC Application (where is Umbraco already installed), I created a folder called Controllers and there I put that controller.

  • Micha Somers 134 posts 597 karma points
    Jun 15, 2016 @ 14:05
    Micha Somers
    0

    The code you wrote for the controller is ok.

    It looks like it can't find the controller. Or maybe there's another route hijacking in place. Something related to languages maybe? Did you define multiple languages or cultures?

  • Mihail 39 posts 142 karma points
    Jun 15, 2016 @ 14:29
    Mihail
    0

    I created simply a document type called language... I could rename to other string. if help...Do I have register something when application starts or something similar ?

  • Micha Somers 134 posts 597 karma points
    Jun 15, 2016 @ 15:00
    Micha Somers
    0

    If the name of your DocumentType is Language (alias = language), there's no reason to rename it. And there is no registration involved either.

    Just to verify if Language as name would be a problem, I've tried it myself (in Umbraco 7.4.3) with a document type named Language, a content node named EN and a controller called LanguageController (in my case defined in a class library).

    After rebuild and run, the LanguageController.Index method is being called successfully when going to the page (http://mywebsite/en)

    Your page renders fine, even though it does not reach your controller code?

    What is the name of the template being used for the published EN node?

    And what version of Umbraco are you using?

  • Mihail 39 posts 142 karma points
    Jun 15, 2016 @ 15:24
    Mihail
    0

    I'm using version 7.4.2... Strange thing...

  • Micha Somers 134 posts 597 karma points
    Jun 15, 2016 @ 16:05
    Micha Somers
    0

    Although https://our.umbraco.org/forum/using-umbraco-and-getting-started/75998-update-to-742-all-custom-hijacked-controllers-stopped-working is not exactly about this scenario, there are other routing related scenarios that have been fixed in version 7.4.3.

    Maybe give that version a try?

  • Mihail 39 posts 142 karma points
    Jun 16, 2016 @ 07:40
    Mihail
    0

    I make it works to link to Index action of LanguageController class.

    I had an old route definition and I removed it.

    So, for Index works.

    I have another question.

    If I go to http://mywebsite/en then LanguageController is instantiated and Index action is called.

    I created a sub-node for en called products and url is

    http://mywebsite/en/products

    I created Products action but it is never called. I have Products as template.

    Why ? What is the logic ?

  • Micha Somers 134 posts 597 karma points
    Jun 16, 2016 @ 09:06
    Micha Somers
    1

    From your url, it looks like Products does not have DocumentType Language but a DocumentType that is a child of DocumentType Language. (Otherwise, the url would be http://mywebsite/products)

    For another DocumentType you need another Controller with the (alias)name of that DocumentType.

Please Sign in or register to post replies

Write your reply to:

Draft