4

i am adding Custom View/Model to Tridion Reference Implementation, but getting error log:

Error adding view model to registry using view path ~/Areas/Custom/Views/Entity/Custom.cshtml The type or namespace name 'Custom' could not be found (are you missing a using directive or an assembly reference?)

  1. created schema
  2. created component template with MVC metadata ViewName is Custom
  3. created View under View Entity folder

what i am missing here? how to add Custom model thanks

  • 1
    Looks like you forgot to add Model class. See my post below where I specified all steps and provided a link to documentation. – Stan Kroshchenko Feb 4 '15 at 0:35
  • i got it working, Model is not in right location, thanks everyone – Lucas Liu Feb 4 '15 at 21:41
5

I have seen this exception multiple times when there is some error in the View. If you check details of your exception, in InnerException you will find more information about your error, that will help to fix it.

enter image description here

Yes, you missing some steps where you need to publish "Publish Settings" page and create Model class in web application

  1. Create Schema
  2. Create Component Template with MVC metadata
  3. Create Component based on your schema
  4. Add Component with ComponentTemplate to a page
  5. Publish page
  6. Publish settings by publishing _System\Publish Settings page
  7. Refresh Web Application settings, go to URL /admin/refresh in your application
  8. Create MVC Model for your schema as described in documentation
  9. Create View
  10. Run and test your page
5

As Stan said it looks like you have missed some steps out. The documentation contains a really good step by step example to add a new schema, model and view. It will help you to follow this as an example first to understand all the parts required.

If you have created a model, make sure its referenced correctly at the top of your view either by having a fully namespace qualified name:

@model My.Namespace.ModelClassName

...or by adding the namespace to the web.config in your Views folder in the MVC application. In the view:

@model ModelClassName

Extract from web.config in the Views folder of the Area where you put the view:

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <namespaces>
            <add namespace="My.Namespace"/>
        </namespaces>
    </pages>
</system.web.webPages.razor>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.