0

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.

Digbyswift
  • 10,310
  • 4
  • 38
  • 66
Ithalica
  • 13
  • 5
  • You have an actionlink, which just renders an anchor. When clicking the anchor, it is always a `[HttpGet]`, so the `[HttpPost]` shouldnt be there. – devqon Aug 28 '14 at 08:35

2 Answers2

0

@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.

devqon
  • 13,818
  • 2
  • 30
  • 45
  • Thanks for your reply. In that case I see an option in making it a get, and doing a redirect to current node id. I just don't see that being a pretty solution. Is it alternatively possible to to overwrite the action executed on submit? – Ithalica Aug 28 '14 at 09:03
  • Yes that is also possible. You can give specific values to the submit buttons and get those variables in the action. Then you can check if the action was meant as a submit or as a reset. For that see the answer of Digbyswift. – devqon Aug 28 '14 at 09:15
0

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.

Community
  • 1
  • 1
Digbyswift
  • 10,310
  • 4
  • 38
  • 66