Cannot access @Umbraco.Field in partial view that calls controller in Umbraco 7
Hi, I created a simple Contact Form in umbraco 7 with a Surface controller, a parital View and a Partial macro view. The partial view is a typical view like this:
@using Umbraco.Web
@model Umbraco7Cms.ViewModels.ContactViewModel
@if ( TempData[ "success" ] == null )
{
using ( Html.BeginUmbracoForm( "SubmitContactForm", "Communication" ) )
{
@Html.AntiForgeryToken()
@Html.ValidationSummary( true )
... labels and input fields come here
}
else
{
<a href="#confirmation"></a>
<p>@Umbraco.Field("EmailConfirmationText")</p>
}
I want to be able to access the document properties but the call @Umbraco.Field() is unknown allthough I included the Umbraco.Web namespace.
How can I access the document properties and dictionary items in from within this partial view? Thank you very much.
This does not work because the partial view does not inherit from Umbraco.Web.Mvc.UmbracoTemplatePage. It defines a viewmodel (@model Umbraco7Cms.ViewModels.ContactViewModel).
This view is rendered in a Macro Partial View like this:
If I figure out how to deal with it I will let you know but my guess is that Jeavon (Or some of the other bright minds in here) will provide an answer before I manage to find out :D
@Gert, you need to replace your @model Umbraco7Cms.ViewModels.ContactViewModel with @inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco7Cms.ViewModels.ContactViewModel> now you can access the UmbracoHelper on @Umbraco but your partial view still expects your custom Model
Jeavon, I tried to give you a high five, but apperently it doesn't get saved. Every time I refresh the browser the "You rock!" disappears ... nevertheless: you rock! ;-)
Cannot access @Umbraco.Field in partial view that calls controller in Umbraco 7
Hi, I created a simple Contact Form in umbraco 7 with a Surface controller, a parital View and a Partial macro view. The partial view is a typical view like this:
I want to be able to access the document properties but the call @Umbraco.Field() is unknown allthough I included the Umbraco.Web namespace.
How can I access the document properties and dictionary items in from within this partial view? Thank you very much.
Kind Regards, Gert.
Hi Gert
Seems like some of your post is missing?
/Jan
Hi Jan, I completed it in the mean while ;-). Thanks!
Hi Gert
You should be able to access document type properties by writing @CurrentPage.propertyname and in regards to fetching dictionary items I think this piece of documentation can help you http://our.umbraco.org/documentation/reference/templating/macros/razor/using-dictionary-items
You can read more about accessing the properties here as well http://our.umbraco.org/documentation/reference/Templating/Mvc/views
Hope this helps :)
/Jan
Hi Jan,
This does not work because the partial view does not inherit from Umbraco.Web.Mvc.UmbracoTemplatePage. It defines a viewmodel (@model Umbraco7Cms.ViewModels.ContactViewModel).
This view is rendered in a Macro Partial View like this:
So the ViewModel can be passed. So when I use @CurrentPage.propertyname, I get an error stating that CurrentPage does not exist.
Any idea how to make this work?
Thanks Gert.
Aah, Sorry Gert - Misunderstood your question!
If I figure out how to deal with it I will let you know but my guess is that Jeavon (Or some of the other bright minds in here) will provide an answer before I manage to find out :D
Cheers, Jan
OK, thanks Jan!
Cheers, Gert.
@Jan, sounds like a carrot on a stick :-)
@Gert, you need to replace your
@model Umbraco7Cms.ViewModels.ContactViewModel
with@inherits Umbraco.Web.Mvc.UmbracoViewPage<Umbraco7Cms.ViewModels.ContactViewModel>
now you can access the UmbracoHelper on @Umbraco but your partial view still expects your custom ModelJeavon
Oh, it's as simple as that! Thanks Jeavon!
Regards, Gert
Jeavon, I tried to give you a high five, but apperently it doesn't get saved. Every time I refresh the browser the "You rock!" disappears ... nevertheless: you rock! ;-)
Gert.
No worries, I think maybe you need 70 karma to h5 but I'm not sure, @Jan might know?
However you should be able to mark the solution using the green tick on the correct answer.
Jeavon
is working on a reply...