Child action is called instead of HttpPost action when submit button is click?
HI,
Using Umbraco 7.1.4 I've created myself a SurfaceController to test
out the creation of new members and logging in.I don't know why child action is called instead of httppost action when submit button is click.
Your method names are OK as they are, because the signatures between the two are different.
Your problem looks like your form submit button is performing an Http GET. You need it to perform an Http POST.
I've tried that and finally found out the problem is caused by html <form> tag as you mentioned.
@using (Html.BeginUmbracoForm<ICB2015_U7.Controllers.RegistrationLoginSurfaceController>("Register"))//this is work fine @using (Html.BeginUmbracoForm("Register", "RegistrationLoginSurface", new { role = "form" }))//this is work fine @using(Html.BeginUmbracoForm("Register","RegistrationLoginSurface"))//this is work fine { <form role="form">//i've removed this //some html helper . . . </form>//i've removed this }
Anyway, I still wonder "What is the difference between submit with <form> and without <form>?"
And this render action code
@using (Html.BeginUmbracoForm("Register", "RegistrationLoginSurface", new { role = "form" }))
means submit with <form>, isn't it?
If the answer is yes, thus, these render action codes
The BeginUmbracoForm helper method is just another way of writing a form tag.
If you view the source code of your website, you will probably see something like this in place of your @using (Html.BeginUmbracoForm) code:
<form action="/" enctype="multipart/form-data" method="post">
<!-- some stuff -->
</form>
In your example, you wanted to specifically hit the [HttpPost] action in your controller. However, because your form tag did not specify a method, the default of HttpGet was being used.
You could either do this using the helper:
Child action is called instead of HttpPost action when submit button is click?
HI,
Using Umbraco 7.1.4 I've created myself a SurfaceController to test out the creation of new members and logging in.I don't know why child action is called instead of httppost action when submit button is click.
Here is all my code:
test\Controllers\RegistrationLoginSurfaceController.cs
test\Views\Partials\RegistrationLoginView.cshtml
test\Views\Registration.cs
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "WeProDefaultSidebarcshtml.cshtml";
}
@Html.Action("Register", "RegistrationLoginSurface")
Any suggestion?
Hi Arcuha,
Try changing the method name of your HttpPost method. I have a feeling it has to be different than the HttpGet method name.
Thanks, Dan.
Hi Dan,
Thank you for your quick reply.
There is nothing change.
I've changed HttpPost action from "Register" -> "RegisterSomeSuffix".
It still call child action instade of HttpPost. T^T
Any other clue?
Hi Arucha,
Your method names are OK as they are, because the signatures between the two are different. Your problem looks like your form submit button is performing an Http GET. You need it to perform an Http POST.
I would fix this by removing the
Hi Hywel,
Thank you for your trick.
I've tried that and finally found out the problem is caused by html <form> tag as you mentioned.
Anyway, I still wonder "What is the difference between submit with <form> and without <form>?"
And this render action code
@using (Html.BeginUmbracoForm("Register", "RegistrationLoginSurface", new { role = "form" }))
means submit with <form>, isn't it?
If the answer is yes, thus, these render action codes
@using (Html.BeginUmbracoForm("Register", "RegistrationLoginSurface"))
and
are submit without <form>, aren't they?
Thank you very much again.
Cheers,
Arucha
Hi Arucha,
The BeginUmbracoForm helper method is just another way of writing a form tag. If you view the source code of your website, you will probably see something like this in place of your @using (Html.BeginUmbracoForm) code:
In your example, you wanted to specifically hit the [HttpPost] action in your controller. However, because your form tag did not specify a method, the default of HttpGet was being used. You could either do this using the helper:
Or
Or, an equally valid fix would have been to add a method attribute to your form tag:
You can do it either way, but I tend to prefer using the helper methods if I can.
Cheers,
Hywel
Hi Hywel,
Thank you for your reply.
It make me understand more clearly.
Inaddition, in httppost action method, I've changed return partialview() to return CurrentUmbracoPage()
follow this link http://our.umbraco.org/documentation/Reference/Mvc/forms
is working on a reply...