@using MensSection.Models
@inherits Umbraco.Web.Mvc.UmbracoViewPage<TourViewModel>
@{
Layout = "CalendarLayout.cshtml";
}
@section Main
{
<div class="col-xs-12">
@using (Html.BeginUmbracoForm("Register", "Tour"))
{
string btnClass = "btn btn-primary";
if (!Model.IsLoggedIn)
{ btnClass += " disabled"; }
@Html.HiddenFor(m => m.SelectedText)
@Html.HiddenFor(m => m.TourId)
<div class="form-group row">
<div class="col-sm-6 dropdown" id="inputTour">
<button class="btn btn-primary"
id="selectButton"
data-toggle="dropdown">
Arrangement
<span class="caret"></span>
</button>
<ul class="dropdown-menu scrollable-menu" id="ulGenres">
@foreach (var item in Model.Tours)
{
<li>
<a href="#" data-pdsa-dropdown-val="@item.Id">@item.StringValue</a>
</li>
}
</ul>
</div>
<div class="col-sm-6">
<button type="submit" name="Command" value="Register" class="@btnClass">Tilmeld / Afmeld</button>
</div>
</div>
if(!Model.IsLoggedIn)
{
<span class="text-warning">Du skal være logget ind for at kunne tilmelde dig til arrangementer</span>
}
}
<div id="Details" class=""></div>
</div>
}
@section script
{
<script type="text/javascript">
function DataLoad() {
var id = $("#TourId").val();
$("#Details").load('/umbraco/Surface/Tour/GetTourDetails?tourId=' + id);
}
$(document).ready(function () {
$("#ulGenres li a").on("click", function () {
// Get text from anchor tag
var id = $(this).data('pdsa-dropdown-val');
$("#TourId").val(id);
// Add text and caret to the Select button
var text = $(this).text();
$("#selectButton").html(text + ' <span class="caret"></span>');
// Put text into hidden field from model
$("#SelectedText").val(text);
DataLoad();
});
var id = $("#TourId").val();
$("#ulGenres li a").filter("[pdsa-dropdown-val= " + id + "]").trigger("click");
});
</script>
}
All looks great at first glance. Maybe this a wild suggestion, but is your HttpPost attribute on the action from the System.Web.Mvc namespace. There is also one in the System.Net.Http namespace meant for WebApi controllers ?
That seams okay. Can you try to remove the model parameter from the post action to see if it get's hit then ? I had troubles sometimes in the past the model binding on post didn't work and that caused my post action not being hit.
BeginUmbracoForm renders wrong action
Hi I'm using BeginUmbracoForm and suddenly it does not render the action using the surfacecontroller and the specified action like this
form action="/umbraco/Surface/Tour/Register" method="post"
as expected from this
It renders the original url to the current for the current document.
When I change it to this
the correct action is rendered, but then I miss the UmbracoContext in the Register implementation.
If I insert another controller that works in another view it also renders the wrong action.
/Paul S
Hi Paul
Does the form post back to your surface controller if you submit it ?
the routing values are encoded in the ufprt hidden field, which is generated by Html.BeginUmbracoForm
If you have at look at the source for RenderRouteHandler:
https://github.com/umbraco/Umbraco-CMS/blob/4a101786972bb591bb5d22acd043cc9f9da267ed/src/Umbraco.Web/Mvc/RenderRouteHandler.cs
you can see where the hidden field is being read, decoded and the route is resolved...
regards
Marc
Hi
I does not post back to my controller. I have get methods on my controller which get hit but not this post method.
I can see the field if I inspect the html, but isn't the important thing here what's in the action tag. It's wrong because it just shows
Hi Paul,
Have you tried :
Dave
Hi Yes but it makes no difference /Thx
What do you see in the action tag of the rendered form ?
Dave
Hi
This is my form tag
This matches the url in my content.
/Paul S
Hi Paul,
Can you show the code from your controller ?
And maybe the output of the generated form. That way we can look where it goes wrong.
Dave
Hi Dave
The controller is here
The BaseSurfaceController is here
The output of the generated form
and the Tour template
/
hi Paul,
All looks great at first glance. Maybe this a wild suggestion, but is your HttpPost attribute on the action from the System.Web.Mvc namespace. There is also one in the System.Net.Http namespace meant for WebApi controllers ?
Dave
Hi Dave
It is
/Paul S
Hi Paul,
That seams okay. Can you try to remove the model parameter from the post action to see if it get's hit then ? I had troubles sometimes in the past the model binding on post didn't work and that caused my post action not being hit.
Dave
Hi Dave It makes no difference
also tried to change back to
/Paul S
Hi Paul,
Also running out of id's here. Do you have perhaps setup some custom routing that would interfere. Or a IIS redirect ?
Dave
Hi Sometimes it helps leaving things for a some time and then try again. The Register now gets called if I leave out the parameter.
With the parameter in the method I get
I don't understand where the rendermodel comes from because it's a TourViewModel. It inherits from RenderModel - is that the reason?
If I change the parameter to a RenderModel then the method get's called - but then I don't have my custom properties.
/Paul S
Hi Paul,
I think the cause is that your model inherits from RenderModel. The name says it actually it is used for rendering.
I never inherit my models from RenderModel.
Dave
Hi Dave I used your advice together with a more or less rewrite - now it works - thanks for your help.
Guess lesson learned is not to use RenderModel with SurfaceControllers
/Paul S
is working on a reply...