I have a recipe page that uses url rewrites to create user friendly urls. On the recipe page I am using a partial view to implement a recipe review form. The issue I am seeing is that the form action does not pick up the rewritten url.
Here is my Partial View
@inherits UmbracoViewPage<Perdue.Models.ReviewModel>
@{ var ajaxOptions = new AjaxOptions { HttpMethod = "POST", OnSuccess = "feedback" }; }
@using (Ajax.BeginForm("SubmitReview", "Review", ajaxOptions))
{
@Html.AntiForgeryToken();
<div id="review-form-all">
<span class="star-rating-title2 hide-mobile">What Do You Think?</span>
<span class="star-rating-title">Your Rating:</span>
<span class="starRating">
@foreach (var Rating in Model.RatingList)
{
if (Rating.Value == "5")
{
@Html.RadioButtonFor(model => model.Rating, Rating.Value, new { id = Rating.ID, @class = "rating-input", Checked = "checked" })
@Html.Label(Rating.ID, Rating.Value, new { @class = "rating-star" })
}
else
{
@Html.RadioButtonFor(model => model.Rating, Rating.Value, new { id = Rating.ID, @class = "rating-input" })
@Html.Label(Rating.ID, Rating.Value, new { @class = "rating-star" })
}
}
</span>
<div id="review-form">
@Html.EditorFor(m => m.Name, new { htmlAttributes = new { placeholder = "Jane Doe" } })
@Html.ValidationMessageFor(m => m.Name)
@Html.EditorFor(m => m.Email, new { htmlAttributes = new { placeholder = "Email" } })
@Html.ValidationMessageFor(m => m.Email)
@Html.EditorFor(m => m.Comment, new { htmlAttributes = new { placeholder = "Comment" } })
@Html.ValidationMessageFor(m => m.Comment)
<br />
<div>
<span class="in-block"><button type="submit" class="yellow-button">ADD YOUR COMMENT</button></span>
<span class="in-block reviews-label required-field">All fields are required.</span>
</div>
</div>
</div>
<div id="reviewTY">
<p class="review-thank-you">Thank you for sharing your thoughts.</p>
</div>
}
<script>
function feedback(result) {
if (result.success) {
console.log('ok');
} else {
var error = "Error";
if (result.error) {
error = result.error;
}
console.log(error);
}
}
</script>
I think you've got two different problems here, one of them being the ajax form which is the only one I'm going to address.
Your problem is the route which should be something like /umbraco/surface/review/submitreview, but I'll go a little bit further and recommend you not to use the Ajax.BeginForm and instead use your own code to submit the form using Ajax because you'd have more control (I've never been a fan of magical methods).
I created a quick and dirty example similar to yours and it looks like this:
Form Submissions + User Friendly URL
I have a recipe page that uses url rewrites to create user friendly urls. On the recipe page I am using a partial view to implement a recipe review form. The issue I am seeing is that the form action does not pick up the rewritten url.
Here is my Partial View
And my abbreviated Controller code:
What I was seeing before I changed the form to ajax was the action being something like /recipes/title=soup?id=10 instead of /recipes/soup/10/
It would post to the controller but then redirect to the wrong url.
After changing to an Ajax form the action is now /recipes/umbraco/Surface/Review/SubmitReview which throws an 404 error.
Any idea on what the action needs to be here to submit correctly and how to modify the action to do so?
Hi Renee,
I think you've got two different problems here, one of them being the ajax form which is the only one I'm going to address.
Your problem is the route which should be something like /umbraco/surface/review/submitreview, but I'll go a little bit further and recommend you not to use the Ajax.BeginForm and instead use your own code to submit the form using Ajax because you'd have more control (I've never been a fan of magical methods).
I created a quick and dirty example similar to yours and it looks like this:
The form:
The controller:"
The Ajax submit:
This is all you need for the form.
Now, for your friendly URLs, can you explain a little better what you're trying to do?
Cheers,
Cristhian.
1,000 thank you's! With the modifications you suggested it is now working correctly.
is working on a reply...