Could someone tell me where to create the ViewModel and the SurfaceController. I guess the PartialView goes in the /PartialView directory? Or do they have to be in a separate project, built and have the dll dropped into Umbraco's bin folder?
Too many of the docs assume expert knowledge of this stuff, which is fine for a "reference" but not for a "guide". People generally need "guides" as this works as a reference as well.
View models and surface controllers will be compiled code, so really you can put them wherever suits you best. Convention for an MVC project though is to put controllers in a folder called "Controllers" and view models in one called "Models". If you prefer though you can certainly put them in a seperate project and reference that from your web appplication.
So if you add the Controllers and Models directories to the Umbraco install then you'd have to "build" the whole thing? I'm guessing if you put them in a seperate project then you'd lose the ability to code with @Model.Content...etc.? I want to add dropdowns to my forms populated from Umbraco content and am not at all sure where to place the files, hence this question.
Yes, that's right. If you really want or need to avoid Visual Studio, you can put them in the App_Code folder - and they won't then need to be compiled. But really once you get into creating your own controllers and view models I'd suggest you'd want to make use of the benefits VS.Net provides.
A seperate project doesn't prevent you using the @Model. syntax though. So long as the project with the controller classes in is referenced from your web application project that'll work fine.
Well I had code in a seperate project and couldn't access the Umbraco Model at all. I put a seperate question on OUR about it, asking what are the references you need, but so far not had a *successful* answer.
MVC Forms
This document could be helpful if it told you where to put the parts it describes. http://our.umbraco.org/documentation/Reference/Templating/Mvc/forms
Could someone tell me where to create the ViewModel and the SurfaceController. I guess the PartialView goes in the /PartialView directory? Or do they have to be in a separate project, built and have the dll dropped into Umbraco's bin folder?
Too many of the docs assume expert knowledge of this stuff, which is fine for a "reference" but not for a "guide". People generally need "guides" as this works as a reference as well.
Thanks
Hi Craig
View models and surface controllers will be compiled code, so really you can put them wherever suits you best. Convention for an MVC project though is to put controllers in a folder called "Controllers" and view models in one called "Models". If you prefer though you can certainly put them in a seperate project and reference that from your web appplication.
Andy
Hi Andy,
So if you add the Controllers and Models directories to the Umbraco install then you'd have to "build" the whole thing? I'm guessing if you put them in a seperate project then you'd lose the ability to code with @Model.Content...etc.? I want to add dropdowns to my forms populated from Umbraco content and am not at all sure where to place the files, hence this question.
Craig
Yes, that's right. If you really want or need to avoid Visual Studio, you can put them in the App_Code folder - and they won't then need to be compiled. But really once you get into creating your own controllers and view models I'd suggest you'd want to make use of the benefits VS.Net provides.
A seperate project doesn't prevent you using the @Model. syntax though. So long as the project with the controller classes in is referenced from your web application project that'll work fine.
Andy
Well I had code in a seperate project and couldn't access the Umbraco Model at all. I put a seperate question on OUR about it, asking what are the references you need, but so far not had a *successful* answer.
Thanks for your repy, it's been helpful.
Craig
Hi you can look at: http://www.charlesafford.com/setting-up-and-using-your-first-surface-controller.aspx
That will tell you basically how to create a surface controller and a view with a partial view and model.
Basically:
ViewModel is a c# class with public properties and other methods.
public class MyViewModel
{
public string FirstName{get;set;}
}
You can use this in a partial view using @model directive
@model MyViewModel
@{
<h1>@Model.FirstName</h1>
}
Surface controller is a class (c#) that implments SurfaceController and has a public method that returns and ActionResult
public mysurfacecontroller : SurfaceController
{
public ActionResult MyActionResult(myViewModel viewModel)
{
return PartialView("your partial view)
}
}
Hope this helps :).
Charlie.
is working on a reply...