Reputation: 13
I am setting up a solution in umbraco using MVC seriously for the first time. I have managed to render a form using BeginUmbracoForm, and submit data, which works wonders.
My issue is, I want to implement a reset button, but since my data is in Session, I have to reset server side.
View:
@using (Html.BeginUmbracoForm<Site1.Controllers.SearchCriteriaSurfaceController>("Search")) { @*Form here*@ @Html.ActionLink("Reset criterias", "Reset", "SearchCriteriaSurface", new {}, null) <input class="btn btn-primary" type="submit" value="Search now" /> }
Controller:
public class SearchCriteriaSurfaceController : SurfaceController { [HttpPost] public ActionResult Search(SearchParams model) { SearchParams.Params = model; ViewBag.HasSought = true; return CurrentUmbracoPage(); } [HttpPost] public ActionResult Reset() { SearchParams.ResetParams(); return CurrentUmbracoPage(); } }
On click, I then get redirected to /umbraco/Surface/SearchCriteriaSurface/Reset which is a resource that cannot be found.
Any idea how I go about reloading the page after hitting the reset button?
Thanks for your time.
Upvotes: 0
Views: 2028
Reputation: 10400
You have two options (certainly more but I can't be bothered to think of them):
1 You can submit using two different buttons
<button type="submit" name="SubmitAction" value="Reset">Reset</button>
<button type="submit" name="SubmitAction" value="Submit">Submit</button>
In your view model you would just need a 'SubmitAction' property and in the action you could test for this value. See here for more detail on the discussion: How do you handle multiple submit buttons in ASP.NET MVC Framework?
2 Use a separate form
You could just have a separate form (hidden) entirely and use javascript to trigger the submittal of the form when you click on the "Reset" anchor.
Upvotes: 0
Reputation: 13997
@Html.ActionLink
renders an anchor. An anchor is not a form, and is not able to redirect to a HttpPost
action.
Either remove the HttpPost
or create a new form for the reset functionality.
Upvotes: 0