I've working on a project where I've implemented Route Hijacking on a Template basis with my own custom ViewModel inheriting from RenderModel.
The url displayed to the user is /members/admin/{route parameter}/edit which is rendered successfully via a Controller I have put together that inherits from RenderMvcController. The template displayed contains a simple form which posts to a Controller that inherits from SurfaceController.
If I use a @Html.BeginUmbracoForm form on this template then the post back to the controller is successful however as soon as I change this to a @Ajax.BeginForm the form doesn't appear to submit. When I look at Chrome's console I can see the submit returns a 500 error with a System.NullReferenceException thrown within the ViewModel's default constructor:
public class EditViewModel : RenderModel
{
public EditViewModel() : base(UmbracoContext.Current.PublishedContentRequest.PublishedContent) { }
public EditViewModel(IPublishedContent content) : base(content) { }
}
I'm guessing that as this is an AJAX post that the UmbracoContext is lost so my question is how do I get around this? I could go with one View Model for display purposes that inherits from RenderModel and then a separate one to use for the form post that doesn't inherit from RenderModel but that seems like a bit of a hack.
Did you use RenderMvcController to post from your form? Or simply SurfaceController?
For me SurfaceController works as it should, as route hijacking isn't needed.
But that's not the case with RenderMvcController and I am not sure if this is the best solution.
Route Hijacking Ajax Form Posting Problem
I've working on a project where I've implemented Route Hijacking on a Template basis with my own custom ViewModel inheriting from RenderModel.
The url displayed to the user is /members/admin/{route parameter}/edit which is rendered successfully via a Controller I have put together that inherits from RenderMvcController. The template displayed contains a simple form which posts to a Controller that inherits from SurfaceController.
If I use a @Html.BeginUmbracoForm form on this template then the post back to the controller is successful however as soon as I change this to a @Ajax.BeginForm the form doesn't appear to submit. When I look at Chrome's console I can see the submit returns a 500 error with a System.NullReferenceException thrown within the ViewModel's default constructor:
I'm guessing that as this is an AJAX post that the UmbracoContext is lost so my question is how do I get around this? I could go with one View Model for display purposes that inherits from RenderModel and then a separate one to use for the form post that doesn't inherit from RenderModel but that seems like a bit of a hack.
Any ideas?
Okay. Managed to sort this. Too much to post here so I'll blog about it when I have a moment and provide a link to the solution.
Any chance of that blog post Craig ? lol
Hi Craig,
Did you use RenderMvcController to post from your form? Or simply SurfaceController?
For me SurfaceController works as it should, as route hijacking isn't needed. But that's not the case with RenderMvcController and I am not sure if this is the best solution.
Did you figure out anything?
is working on a reply...