I was trying to add a new MVC template to an existing site that I've been developing for the last few months. I have a couple custom controllers/models setup that are working fine. Today I tried to add another new template and I've run into this error that I can't get past. Umbraco version is 7.04.
First, the error:
http://i.imgur.com/iH6cmUD.png
~/Views/MVCTest.cshtml
@inherits Umbraco.Web.Mvc.UmbracoViewPage<TestModel>
@{
Layout = null;
}
<h1>Hello, World!</h1>
~/App_Code/Test/TestController.cs
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
public class TestController : RenderMvcController {
public override ActionResult Index(RenderModel model) {
var test = new TestModel(model.Content, model.CurrentCulture);
return base.Index(test);
}
}
~/App_Code/Test/TestModel.cs
using System.Globalization;
using Umbraco.Core.Models;
using Umbraco.Web.Models;
public class TestModel : RenderModel {
public TestModel(IPublishedContent content, CultureInfo culture)
: base(content, culture) {
}
}
Anybody see any obvious issues? It's really strange because I have essentially the same exact code working for some other custom models and controllers so I'm totally confused as to why any new types give me this error.
Your code is almost right, the problem is that your view is called MVCtest.cshtml
because presumably your document type is called MVCtest
, however your Controller is just called TestController
and not MVCTestController
.
Umbraco's routing is quite specific in that it will route all traffic for a specific document type via a controller with a matching name.
Also, you don't need the return base.Index(test);
, just return CurrentTemplate(test);
An additional point is that Umbraco will by default attempt to route via the Index
action unless you have actions that match the name of your templates. So, you could have multiple templates each with separate actions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With