The model element passed to the dictionary is of type "Umbraco.Web.Models.RenderModel", but this dictionary requires a model element of type "TestModel"

I was trying to add a new MVC pattern to an existing site that I have been developing for the past few months. I have a couple of custom controllers / models that are working fine. Today I tried to add another new template and I ran into this error which I cannot get through. Umbraco version is 7.04.

First, the error:

http://i.imgur.com/iH6cmUD.png

<strong> ~ / 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) {

    }

}

      

Does anyone see any obvious problems? This is really weird because I have the exact same code that works for some other custom models and controllers, so I am totally confused as to why any new types are giving me this error.

+3


source to share


2 answers


Your code is almost correct, 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

, not MVCTestController

.

Umbraco's routing is quite specific in that it will route all traffic for a specific document type using a controller with the appropriate name.



Also, you don't need return base.Index(test);

, justreturn CurrentTemplate(test);

An additional point is that Umbraco will by default try to route through an action Index

if you don't have an action matching your template name. This way you can have multiple templates with separate actions.

+5


source


Don't need TestModel

two (2) constructors ?



0


source







All Articles