I have tried to find an aswer to this for hours with no luck, not sure if I'm doing something wrong (probably) or it's some caveat of Umbraco.
The thing is that I want to avoid partial views usign route hijacking. Just for clarity I don't want to have a template that the only thing it does is render a child action.
So I have created my mvc controller like this:
public class MembershipController : RenderMvcController
{
public ActionResult MemberSignUp(RenderModel renderModel)
{
var model = new MemberSignupViewModel(renderModel.Content);
return CurrentTemplate(model);
}
}
The surface controller where I want to post the form to:
public class MembershipFormsHandlerController : SurfaceController
{
[HttpPost]
public ActionResult MemberSignUp(MemberSignupViewModel model)
{
//Member sign up code
}
}
My view model:
public class MemberSignupViewModel : RenderModel
{
public virtual string Password { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public MemberSignupViewModel(IPublishedContent content) : base(content)
{
}
}
The form renders properly but when I submit it I get the error:
Cannot bind source type Umbraco.Web.Models.RenderModel to model type TNT.TopCoach.ViewModels.MemberSignupViewModel.
I guess the way the Umbraco routing works it is trying to send a RenderModel to my controller. Is there any way to return the view model?
Just for testing I have tried to inherit my view from UmbracoTemplatePage. Obviously I lose my strongly typed model but I can create an empty view model to create my form.
This works ok for this example but what about if I want to create a form to edit my members details? Is there anyway to get the populated view model without using partial views?
Submitting form with custom model
I have tried to find an aswer to this for hours with no luck, not sure if I'm doing something wrong (probably) or it's some caveat of Umbraco.
The thing is that I want to avoid partial views usign route hijacking. Just for clarity I don't want to have a template that the only thing it does is render a child action.
So I have created my mvc controller like this:
The surface controller where I want to post the form to:
My view model:
And my view:
The form renders properly but when I submit it I get the error:
Cannot bind source type Umbraco.Web.Models.RenderModel to model type TNT.TopCoach.ViewModels.MemberSignupViewModel.
I guess the way the Umbraco routing works it is trying to send a RenderModel to my controller. Is there any way to return the view model?
Just for testing I have tried to inherit my view from UmbracoTemplatePage. Obviously I lose my strongly typed model but I can create an empty view model to create my form.
This works ok for this example but what about if I want to create a form to edit my members details? Is there anyway to get the populated view model without using partial views?
is working on a reply...