PublishedContentModel used in UmbracoApiController gives NULL
I have the following
public class NewsletterApiController : UmbracoApiController
{
public string SaveOptin(NewsletterOptin optin)
{
return "ok";
}
}
NewsletterOptin is a generated Model through the LiveAppData. When I send data through ajax to the controller I get "Object reference not set to an instance of an object." for the parameters of the model.
The error occurs on this generated code:
///<summary>
/// Email
///</summary>
[ImplementPropertyType("email")]
public string Email
{
get { return this.GetPropertyValue<string>("email"); }
}
Is this not possible? Or am I doing something wrong?
You cannot use the Models Builder models in this context. They are meant to provide read-only access to published content (notice how in the generated property only the get is implemented and not the set).
What you need to do is create your own model class containing all the properties you want to bind and then use that as the parameter to the method.
Have a look at using PetaPoco (shipped with Umbraco) to save these to a custom database table. You could then use either Fluidity or UI-O-Matic to make the data available in the backoffice.
PublishedContentModel used in UmbracoApiController gives NULL
I have the following
NewsletterOptin is a generated Model through the LiveAppData. When I send data through ajax to the controller I get "Object reference not set to an instance of an object." for the parameters of the model.
The error occurs on this generated code:
Is this not possible? Or am I doing something wrong?
I send my data like so:
You cannot use the Models Builder models in this context. They are meant to provide read-only access to published content (notice how in the generated property only the
get
is implemented and not theset
).What you need to do is create your own model class containing all the properties you want to bind and then use that as the parameter to the method.
Also, you may want to reconsider saving these form submissions as content nodes (I'm guessing that's what you are trying to do) for the reasons mentioned here: https://our.umbraco.org/documentation/reference/Common-Pitfalls/#using-umbraco-content-items-for-volatile-data
Have a look at using PetaPoco (shipped with Umbraco) to save these to a custom database table. You could then use either Fluidity or UI-O-Matic to make the data available in the backoffice.
is working on a reply...