Copied to clipboard

Flag this post as spam?

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


  • Jonathan Roberts 409 posts 1063 karma points
    Nov 26, 2014 @ 12:51
    Jonathan Roberts
    0

    How to create a Partial view using Visual Studio MVC

    Hi,

    I am very new to Umbraco 7 and to MVC and I would like to create a new Partial View / new feature using Visual Studio and MVC. I would like to know if I need to create a new MVC project in VS, install the Umbraco CMS packages and then create a Model, Controller and View in the MVC project? Is this possible and is there any documentation on this?

    I have looked at : http://our.umbraco.org/documentation/Reference/Mvc/forms/turorial-partial-views

    but I am not 100% sure how this is implemented into my existing MVC project and how I can implemnt this into the Umbraco CMS/Site.

    Many thanks

     

    Jonathan

  • Ayo Adesina 445 posts 1059 karma points
    Nov 26, 2014 @ 14:11
    Ayo Adesina
    0

    Hi Jonathan,

    This is what I usually do, others may do it differently but this is what works for me.

    1. Set up an Empty MVC application
    2. Install Umbraco Via Nuget
    3. Run the website, go through the installation wizard.
    4. Delete the install folder

    At this stage you will have a new umbraco website, if you want to create your own controllers you need to understand the concept of surface controllers

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

    Go from there. - Good luck

    Ayo

  • Jonathan Roberts 409 posts 1063 karma points
    Nov 26, 2014 @ 15:36
    Jonathan Roberts
    0

    Hi, Many thanks for this.

    I have created the steps that you mention above. Then in my source I created a new Models folder where I have added in a new Model class.

    for example:

    namespace UmbracoSiteExample.Models

     

    {

    publicclassumbEmailerViewModel

     {

    publicstring Name { get; set; }

     publicstring Email { get; set; }

     publicstring Message { get; set; }

     }

    }

     

    I have a new Controller folder with a new controller class and I created a Partial cshtml file in the Views/Partials folder.

    To see my new @model I have to reference the controller and model by the following two lines:

     

     

     

     

    @using UmbracoSiteExample.Controllers

    @using UmbracoSiteExample.Models

    But when I run the site it doesnt work and I get the following error:

     

    The type or namespace name 'UmbracoSiteExample' could not be found (are you missing a using directive or an assembly reference?)

     

    Am I missing something?

     

     

     

    Many thanks

     

     

     

    Jon

     

     

     

     

     

     

     

     

  • Ayo Adesina 445 posts 1059 karma points
    Nov 26, 2014 @ 17:01
    Ayo Adesina
    0

    Are the controllers in a separate project? If so you will have to add a reference to it. Right click on the web project and then click references.

    Regards Ayo

  • Joshua Walsh 30 posts 151 karma points
    Feb 24, 2015 @ 06:10
    Joshua Walsh
    0

    Just found this thread, I have the same issue. My models are in the same project as everything else.

    I made a thread for my problem here, before I discovered this thread: https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/61638-Where-to-put-Models-in-Umbraco-7

    Did you ever work out what was wrong, Jon?

    EDIT: I solved my problem, maybe it will help you too? See my last post at the above link.

Please Sign in or register to post replies

Write your reply to:

Draft