Access Document Type Properties from MVC Controller
Hi,
I have a Contact Form that when submitted I want the Controller Action to look at a property of the current doc type (the contact form doctype) and get a property (the email address to send from) to create the Mail object.
I'm stuck on how to do this. Any suggesstions?
I don't want to pass this in as a Route Value as it is an ajax form on the front end and the Route Value properties would be abailable in the html source.
I am posting to a Surface Controller. I tried your solution and the error I'm getting back is:
Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request
My Controller is declared like so:
public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
[HttpPost]
public ActionResult SendMail(Contact form)
{
var test = CurrentPage.GetPropertyValue<string>("myTestProperty");
}
}
I wasn't able to get to the bottom of this the way I would have liked. My issue does not seem to be down to the Umbraco behaviour noted in your first link. I think that the root of is might be in me using @Ajax.BeginForm instead of @BeginUmbracoForm. But for my purposes I wanted to use @Ajax.BeginForm.
I have resolved it now by passing in the node id as part of the form post vars. Then within the Controller I grab the Umbraco node of that ID and query the property that I want to get:
It's probably because BeginUmbracoForm has a special token which the default Ajax.BeginForm doesn't have. Maybe this issue can help: http://issues.umbraco.org/issue/U4-1458
Access Document Type Properties from MVC Controller
Hi,
I have a Contact Form that when submitted I want the Controller Action to look at a property of the current doc type (the contact form doctype) and get a property (the email address to send from) to create the Mail object.
I'm stuck on how to do this. Any suggesstions?
I don't want to pass this in as a Route Value as it is an ajax form on the front end and the Route Value properties would be abailable in the html source.
Cheers :)
Hello,
Do you post to a Surface Controller? In there you have the CurrentPage property in which you can acces properties of your current node.
For example:
Jeroen
Hi Jeroen thanks for getting back to me.
I am posting to a Surface Controller. I tried your solution and the error I'm getting back is:
Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request
My Controller is declared like so:
I'm rendering the form in a partial like this
Any idea why I can't access the property?
Hello,
Maybe these topics can help:
http://our.umbraco.org/forum/ourumb-dev-forum/bugs/44643-umbraco-route-def-missing-from-RouteDataDataTokens
http://stackoverflow.com/questions/17532639/basic-umbraco-6-1-1-surfacecontroller-questions
Jeroen
Hi Jeroen,
I wasn't able to get to the bottom of this the way I would have liked. My issue does not seem to be down to the Umbraco behaviour noted in your first link. I think that the root of is might be in me using @Ajax.BeginForm instead of @BeginUmbracoForm. But for my purposes I wanted to use @Ajax.BeginForm.
I have resolved it now by passing in the node id as part of the form post vars. Then within the Controller I grab the Umbraco node of that ID and query the property that I want to get:
And then in the Controller:
I know it's not ideal but it gets me over this hump!
Thanks again,
Alan
It's probably because BeginUmbracoForm has a special token which the default Ajax.BeginForm doesn't have. Maybe this issue can help: http://issues.umbraco.org/issue/U4-1458
Jeroen
That could be it alright :)
Hello,
Could you mark a post as resolved if it helped you?
Jeroen
Don't forget to re-add/not-delete the two keys below in the Web.config if your using @Ajax.BeginForm when upgrading. Took hours to realise my mistake!
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
thanks John :)
is working on a reply...