I installed Umbraco 7 inside Visual Studio empty project as per the documents on this site. Started the site and installed a starter kit. All is working as i would expect.
I now create a Model and then create a View within VS. The View has been saved to the default location (Site\Views\CONTROLLER\file.cshtml).
The next step is to log onto the site through a browser and navigated to Settings/Developers and other locations but i cant seem to find the Views i created?
I can see all the Partial Views but not the ones outside of that folder. How do i access/view them within Visual Studio?
Have you created a document type? This will generate a view for you (hidden in VS so you have to show / hide files). Then you build your models using models builder.
It sounds like you've come from a C# background and want to go code first - building models and controllers - that's not how Umbraco works.
I'd suggest you go through the basic tutorial - there will be an "ahh.. that's how it works" moment.
Yes you're correct i usually create Models, Controllers and separate my projects into dlls, using Entity Framework, Unit of work, Unit testing, Dependency Injection. Just mentioning these as i would like to introduce these into Umbraco (hopefully??).
Were starting to go into Umbraco a little more as most things are done relatively quickly compared to certain tasks.
I will go through the link you posted but if there is any other material i could utilise it would be great if you could link anything. We also have a sub to Pluralsight so if theres anything on there i could use again be great for any pointers.
I didnt create a Document Type, all i did was create a Model and then generated a View which showed up in VS but not in the Umbraco site i created. I then added a Template and assigned
@Html.Action("Index", "ContactForm")
Inside the template to display the View. This displayed everything i required but the reason for my question was if i needed another developer who may not have VS (and access to only the Umbraco site as in backend) how could they see this View and make any changes?
You really are best to go through the tutorial - don't try to fight the Umbraco routing.
Doc types are vital to Umbraco - you need these to provide editors with a useable site. Try to park your MVC brain - go slow and go through the tutorials!
Creating the doc type will create a view that other can see in the Umbraco backend. What you created won't because it's not in the root /Views/ folder.
I suggest you then look at the Models builder - it takes your doc types and makes classes for you. You won't need to do too much coding.
Thanks for that and i will go through those tutorials shortly.
So just to make sure I've understood you correctly as i went through a few pages before i felt i may have misled you.
If i wanted to create a contact form, I created a Doc type (Name, Email and Message). This in turn created the Template under the template section with the default Razor code i.e.
Once i have this template, i would still need to carry out some other functionality i.e. send and email and maybe record it in a database of the details entered. So its at this stage i would imagine i need to do some coding - does this sound like were attacking the same goal post? I assume i would then create a controller to for this Template but i wont go there just yet as i assume this is whats covered in the tutorials :-)
Ok a little confused :-( but does this look correct as per my understanding
I will take a look at Surface Controllers for version 7 of Umbraco (https://our.umbraco.com/Documentation/Reference/Routing/surface-controllers) (and the tutorials you mentioned above).
Leave the Doc type in place and use this Doc Type to build the model so it can be used in a class to send an email.
Finally learn on modelBuilders for Umbraco?
If this sounds like im on the right lines then i can mark this as answered.
At first it sounded like you were trying to output content. When you made it clear you were doing a contact form then surface controllers along with custom models (nothing to do with the document type) are the way to do this.
You will likely need a contact us doc type so you can add the partial to render the form but it won't need to add to this doc type the fields that you're planning to capture on the form - these will come from a standard model as per the documentation for surface controllers.
At first it sounded like you were trying to output content. When you made it clear you were doing a contact form then surface controllers along with custom models (nothing to do with the document type) are the way to do this.
Ok so i will look into Surface Controller but my obstacle was with displaying the View within Umbraco. So this would mean theres no way to display the View in Umbraco administrative section?
The only reason i want to display it, is so if there were changes needed i.e. adding some static text on the View it can be done by someone at that level in the company.
If you want additional Umbraco CMSed content within the partial that renders the form (titles, intro text, error codes etc) there's a slight problem as you need to pass the form model (form data) into the partial to render the form and later handle the post and there isn't the chance to pass the Umbraco doc type model in as well.
My usual workaround is in the Surface Controller to populate a ViewModel class with the labels and error text. So in the RenderForm method do something like:
Then create your form model as per the documentation and return that in to the partial view to render your form.
ContactSubmission model = new ContactSubmission();
// prepopulate any form data here
return PartialView("ContactUs/ContactUs", model);
Now in your partial view that renders the form you're still just expecting the form data model:
@model YourNamespace.Models.ContactSubmissions.ContactSubmission
@{
var viewData = ViewData["ContactUsViewData"] as YourNamespace.Models.ContactSubmissions.ContactUsViewModel;
}
... @* form render here use model for the form fields and viewData for labels / titles / error messages etc *@
Does that make sense - you're essentially building a second model, storing it to ViewData so that you can get it again in the partial.
In some situations (AJAX) you might need to add the content node's ID / key to the form data model so that you know where the form has come from so you can get the the correct page's view data. Here you just add it on the render method and then you have it on the post if you get the node using standard Umbraco methods.
I think that makes sense so i will go through the links you posted to follow some steps on this.
One other way i found was to cut the folder from the Views VS location and then paste it within Partial Views which resulted in the file appearing within Umbraco
How to see Views in Umbraco?
I installed Umbraco 7 inside Visual Studio empty project as per the documents on this site. Started the site and installed a starter kit. All is working as i would expect.
I now create a Model and then create a View within VS. The View has been saved to the default location (Site\Views\CONTROLLER\file.cshtml).
The next step is to log onto the site through a browser and navigated to Settings/Developers and other locations but i cant seem to find the Views i created?
I can see all the Partial Views but not the ones outside of that folder. How do i access/view them within Visual Studio?
Hi,
Have you created a document type? This will generate a view for you (hidden in VS so you have to show / hide files). Then you build your models using models builder.
It sounds like you've come from a C# background and want to go code first - building models and controllers - that's not how Umbraco works.
I'd suggest you go through the basic tutorial - there will be an "ahh.. that's how it works" moment.
https://our.umbraco.com/documentation/tutorials/Creating-Basic-Site/
Then look at the models builder.
If you are a c# dev then look at custom controllers and you should see how to do everything you need (and are used to!).
Steve
Hi
Yes you're correct i usually create Models, Controllers and separate my projects into dlls, using Entity Framework, Unit of work, Unit testing, Dependency Injection. Just mentioning these as i would like to introduce these into Umbraco (hopefully??).
Were starting to go into Umbraco a little more as most things are done relatively quickly compared to certain tasks.
I will go through the link you posted but if there is any other material i could utilise it would be great if you could link anything. We also have a sub to Pluralsight so if theres anything on there i could use again be great for any pointers.
I didnt create a Document Type, all i did was create a Model and then generated a View which showed up in VS but not in the Umbraco site i created. I then added a Template and assigned
Inside the template to display the View. This displayed everything i required but the reason for my question was if i needed another developer who may not have VS (and access to only the Umbraco site as in backend) how could they see this View and make any changes?
Thanks
Hi,
You really are best to go through the tutorial - don't try to fight the Umbraco routing.
Doc types are vital to Umbraco - you need these to provide editors with a useable site. Try to park your MVC brain - go slow and go through the tutorials!
Creating the doc type will create a view that other can see in the Umbraco backend. What you created won't because it's not in the root /Views/ folder.
I suggest you then look at the Models builder - it takes your doc types and makes classes for you. You won't need to do too much coding.
For forms look at Surface Controllers.
Hi Steve
Thanks for that and i will go through those tutorials shortly.
So just to make sure I've understood you correctly as i went through a few pages before i felt i may have misled you.
If i wanted to create a contact form, I created a Doc type (Name, Email and Message). This in turn created the Template under the template section with the default Razor code i.e.
Once i have this template, i would still need to carry out some other functionality i.e. send and email and maybe record it in a database of the details entered. So its at this stage i would imagine i need to do some coding - does this sound like were attacking the same goal post? I assume i would then create a controller to for this Template but i wont go there just yet as i assume this is whats covered in the tutorials :-)
Thanks again for your help
As per my post.
For forms - look at Surface Controllers. And no - your model for a user submission would be a more classic c# class.
Ok a little confused :-( but does this look correct as per my understanding
I will take a look at Surface Controllers for version 7 of Umbraco (https://our.umbraco.com/Documentation/Reference/Routing/surface-controllers) (and the tutorials you mentioned above).
Leave the Doc type in place and use this Doc Type to build the model so it can be used in a class to send an email.
Finally learn on modelBuilders for Umbraco?
If this sounds like im on the right lines then i can mark this as answered.
Many thanks
Hi,
Nearly the right lines...
At first it sounded like you were trying to output content. When you made it clear you were doing a contact form then surface controllers along with custom models (nothing to do with the document type) are the way to do this.
You will likely need a contact us doc type so you can add the partial to render the form but it won't need to add to this doc type the fields that you're planning to capture on the form - these will come from a standard model as per the documentation for surface controllers.
Steve
Ok so i will look into Surface Controller but my obstacle was with displaying the View within Umbraco. So this would mean theres no way to display the View in Umbraco administrative section? The only reason i want to display it, is so if there were changes needed i.e. adding some static text on the View it can be done by someone at that level in the company.
Hi,
If you want additional Umbraco CMSed content within the partial that renders the form (titles, intro text, error codes etc) there's a slight problem as you need to pass the form model (form data) into the partial to render the form and later handle the post and there isn't the chance to pass the Umbraco doc type model in as well.
My usual workaround is in the Surface Controller to populate a ViewModel class with the labels and error text. So in the RenderForm method do something like:
Then create your form model as per the documentation and return that in to the partial view to render your form.
Now in your partial view that renders the form you're still just expecting the form data model:
Does that make sense - you're essentially building a second model, storing it to ViewData so that you can get it again in the partial.
In some situations (AJAX) you might need to add the content node's ID / key to the form data model so that you know where the form has come from so you can get the the correct page's view data. Here you just add it on the render method and then you have it on the post if you get the node using standard Umbraco methods.
HTH
Steve
Hi
I think that makes sense so i will go through the links you posted to follow some steps on this.
One other way i found was to cut the folder from the Views VS location and then paste it within Partial Views which resulted in the file appearing within Umbraco
Thanks again
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.