From your explanation, I'm not sure how you are working with Umbraco.
If you have a Visual Studio solution for your project, then you can add a c# class to a folder in your web application solution, and this will automatically generate a namespace for your new class, when the solution is built into a dll, this will include the class and you can use the 'namespace' in the using statement to refer to it in your views/templates.
namespace MyProject.Models {
public class Product
{
public string ProductID { get; set; }
public string ProductName { get; set; }
public string ProductCategory { get; set; }
}
}
and then:
@using MyProject.Models
But because you've mentioned creating it in the Umbraco folder, and refer to it as umbraco.Models... it makes me think you might not be using Visual Studio?
if not then your class won't be compiled...
... but you can have it compile on the fly, if in the root of your project (not the umbraco folder) you have a special called app_code - and anything you put in here will be compiled when your application starts.
So you could then create a product.cs file inside the app_code folder, and put your custom product class implementation in there... without using Visual Studio or similar to do the compilation.
Data Model in Umbraco
Hallo everybody,
I use a specific data model (classes) that I use to fill with Json-Data (Deserialize over Newtonsoft).
At the moment I define this classes in the template with
I would like to put this model somewhere in the project. So I created a folder "Models" in the root folder of Umbraco.
I tried to use that model by putting the folloing using-directive in the template.
This does not seem to work. What do I have to do?
Hi Christian
From your explanation, I'm not sure how you are working with Umbraco.
If you have a Visual Studio solution for your project, then you can add a c# class to a folder in your web application solution, and this will automatically generate a namespace for your new class, when the solution is built into a dll, this will include the class and you can use the 'namespace' in the using statement to refer to it in your views/templates.
and then:
But because you've mentioned creating it in the Umbraco folder, and refer to it as umbraco.Models... it makes me think you might not be using Visual Studio?
if not then your class won't be compiled...
... but you can have it compile on the fly, if in the root of your project (not the umbraco folder) you have a special called app_code - and anything you put in here will be compiled when your application starts.
So you could then create a product.cs file inside the app_code folder, and put your custom product class implementation in there... without using Visual Studio or similar to do the compilation.
regards
Marc
is working on a reply...