Reputation: 2425
I have an Umbraco Cloud Project I have just started, and for the first time I want to use the ModelBinder.
When using Umbraco Cloud you have a website instead of a Web Application.
You also have a .Core Project where you have a controllers folder. How do I access the generated strongly typed classes in my controllers in my .Core project when the classes are generated in the Website project?
Also, in the past before I started using the model binder, I would always make custom view models, do logic in my controller then pass that custom view model to my view.
When using the Model Binder, assuming I can get the strong types classes in my controller, should I still be making a custom view model class now I have a strong typed object can I just pass that straight in to the view... I'm a little confused about the correct approach, my gut is telling me I should still using a custom view model.
Upvotes: 0
Views: 238
Reputation: 2425
OK, Looks like I have got it working but I'm not 100% sure if this is the way it should be done.
Step 1.
Sent Model Binder mode in the web config to DLL with the following settings
<add key="Umbraco.ModelsBuilder.Enable" value="true" />
<add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll" />
This will cause Umbraco to generate model classes based on your Document Types. - (by clicking generate models button) which are located in:
Umbraco.Web.PublishedContentModels.dll in the bin folder. of your .Web project
Step 2
From the .Core project Add a reference to Umbraco.Web.PublishedContentModels.dll the bin folder of the .Web project.
Now in your controller classes in your .core project you can now use your strongly typed Generated model like this:
public ActionResult Index(HomePage model)
{
var myvalue = model.SEotitle; // Look strong typed
//more logic here
return View(model);
}
Would love to know if this is how others are using model binder in cloud.
Upvotes: 0