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) {
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"
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!
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!)
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.
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
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:
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"
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:
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!)
Hi, glad you got it working in the end. I've commented on the other thread about views.
I've also updated the documentation regarding hijacking routes:
http://our.umbraco.org/documentation/reference/mvc/custom-controllers/
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
Are you referring to creating a form to post information to? See: http://our.umbraco.org/documentation/reference/Mvc/forms
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.
Totally, i need to add a bunch of examples :) soon, promise!
is working on a reply...