Copied to clipboard

Flag this post as spam?

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


  • Edwin van Koppen 156 posts 270 karma points
    Nov 15, 2012 @ 17:00
    Edwin van Koppen
    0

    Hijacking routes 4.10.1

    Hi all,

    I've got a problem making http://our.umbraco.org/documentation/reference/mvc/custom-controllers/ to work.

    I got a solution in VS2012 with Umbraco in it's own project and a MVC3 project for the website files. In Umbraco i made a document type "test" and a page with that.

    In the MVC project i made a TestController.cs like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Umbraco.Web.Models;
    using Umbraco.Web.Mvc;

    namespace W3S.Controllers
    {
        public class TestController : RenderMvcController
        {
            public override ActionResult Index(RenderModel model) {

                ViewBag.Test = "test";
                return base.Index(model);
            }
        }
    }

    and a view, with almost nothing in it.If i call the page with /test/ then i got this error:

    "No parameterless constructor defined for this object."

    I think i do not call the page correct with the correct url but how do i let my MVC project know that, that route exists?

    Thx for any answers or thoughts!
    Ed

     

     

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Nov 15, 2012 @ 17:56
    Shannon Deminick
    0

    What is the rest of this stack trace, need more than just the error message.

    I think there is confusion here over what Hijacking routes actually is. A hijacked route DOES NOT match a URL, it matches a document type + a template as per the documentation.

    So for example, if you have a node structure like this in Umbraco:

    - Home (url = "/", document type = "Home")
    -- Test (url = "/test", document type = "Test")

    Then if you have a controller like you've created "TestController", we will then determine that all pages of document type "Test" will be routed to your controller and in this case with the above node structure, this would match for the url "/test", however it will match for any Umbraco URL that is of document type "Test"

     

     

  • Edwin van Koppen 156 posts 270 karma points
    Nov 16, 2012 @ 09:19
    Edwin van Koppen
    0

    Ok, but a url is routed to a document type i presume? So if i make a umbraco path like /this/is/a/doc and it's of a document type "test" it got routed to the "TestController" right?

    I think my problem is that i set up the my project in this (see picture) way, i thought it is a good idee to separate the project because it's a forms and mvc project but then i have very little context. Is it better to make a hybrid project Shannon? My problem is that it's my first Umbraco 4 (have done some testing on 5) project and i want to use MVC but i can't find a example how to set up a complete MVC Umbraco project with my own controllers, Do you have a example Shannon? It would really help me!

    if it helps, here is the stack trace:

     

    [MissingMethodException: No parameterless constructor defined for this object.]
       System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
       System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
       System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
       System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
       System.Activator.CreateInstance(Type type) +6
       System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +177
       System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +514
       System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +374
       System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +296
       System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +105
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311
       System.Web.Mvc.Controller.ExecuteCore() +105
       System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +87
       System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19
       System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
       System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31
       System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
       System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629708
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

  • Edwin van Koppen 156 posts 270 karma points
    Nov 16, 2012 @ 15:15
    Edwin van Koppen
    0

    Got the hijacking working! It's now in it's own project and after the build copied the .dll to the umbraco project. I read that a separte project is a good idea if you want  sourcecontrol so i want to hang on to that idea but now i have a problem with the different way Umbraco save views see: http://our.umbraco.org/forum/using/ui-questions/36217-MVC-views-not-in-subfolder

    (if i got this all running i just need to follow my questions so i can make a blog about this all!)

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Nov 20, 2012 @ 01:08
    Shannon Deminick
    0

    Hi, glad you got it working in the end. I've commented on the other thread about views.

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Nov 20, 2012 @ 01:10
    Shannon Deminick
    0

    I've also updated the documentation regarding hijacking routes:

    http://our.umbraco.org/documentation/reference/mvc/custom-controllers/

     

  • sara 1 post 21 karma points
    Feb 28, 2013 @ 18:21
    sara
    0

    Hi,

    I'm using the hijacking and it works fine. However I don't know how to do a post on the page on a page that uses a custom model.

    Can you please give me an example of that.

    Thanks

    Sara

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Feb 28, 2013 @ 19:03
    Shannon Deminick
    0

    Are you referring to creating a form to post information to? See: http://our.umbraco.org/documentation/reference/Mvc/forms

  • Edwin van Koppen 156 posts 270 karma points
    Feb 28, 2013 @ 21:28
    Edwin van Koppen
    0

    Funny, i'm now trying it also for the first time!

    Maybe direct a question for Shannon, i want to build my own form with inputfields, can you add a example for that? I do think alot of people want to style his own form.

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Feb 28, 2013 @ 21:40
    Shannon Deminick
    0

    Totally, i need to add a bunch of examples :) soon, promise!

Please Sign in or register to post replies

Write your reply to:

Draft