I’m trying to set up a surface controller post endpoint that can be called via a form setup with UmbracoBeginForm but it’s giving me an odd result.
I have a view component that renders the form connected to the controller and method. I verified that the form contains the anti forgery token and what not and that it is posting correctly. However, when it tries to post the browser just loads indefinitely.
The endpoint in the surface controller verifies the anti-forgery token, is set up for post, accepts the correct model, etc.
The odd thing is that if I change the endpoint to be invalid, like change the name or add [FromBody] to the model parameter then the post comes back immesiately with the error code. So, it seems like if everything is working it just hangs.
There’s nothing in the logs, it never actually gets into the controller method because I have a breakpoint on the first line.
If I change the form to be setup with BeginForm and post to the surface controller action directly then it works and sends the model in. However, I don’t have any Umbraco context in that case.
Does anyone know what would cause it to hang forever and never actually reach the controller method when things seem to be set up correctly?
Update: I have a sub-object on my model and it only seems to hang when I supply hidden fields for properties on that object, using something like @Html.HiddenFor(m => m.Object.Property)
If I remove that then it works correctly. What is the best way to handle these sub objects on models? I even tried adding an initializer for the subject as new() so it would never be null but it still hangs.
I actually resolved it today. Apparently it doesn’t like IPublishedContent properties in the model. If I remove those then it works. Then I added them back as read only properties and have a private variable that can be set through a method and it works like that as well.
IPublishedContent are potentially huge models with all kinds of related stuff, so using them as any DTO or as input for controllers and API’s usally isn’t the best option, you’d better of creating models with just the data you need, or passing in the key and get the data when needed.
Yeah, I typically wouldn’t do it this way. However, this is an old v8 site that I’m converting and there is a ton of logic tied to these models that would have to change if I changed the way the models are set up so I figured my other solution was a quick way to make it work as is.