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?
This is what I usually do, others may do it differently but this is what works for me.
Set up an Empty MVC application
Install Umbraco Via Nuget
Run the website, go through the installation wizard.
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
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
Hi Jonathan,
This is what I usually do, others may do it differently but this is what works for me.
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
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
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
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.
is working on a reply...