Your reset
button, is a Form Reset button, that will only empty your form fields, if you want that button to be pressed as well and actually post a form, you have several ways:
way 1 (2 forms):
@using (Html.BeginForm("Boat", "Shipments"))
{
<input type="submit" value="Search" />
}
@using (Html.BeginForm("Reset", "Shipments"))
{
<input type="submit" value="Reset" />
}
way 2 (add name
and check that):
@using (Html.BeginForm("Boat", "Shipments"))
{
<input type="submit" name="submitButton" value="Search" />
<input type="submit" name="submitButton" value="Reset" />
}
public ActionResult Shipments(FormCollection form)
{
if(form["submitButton"] == "Reset") {
// reset was pressed
Session.Remove("SearchBoat"); // remove session
return RedirectToAction("Index"); // redirect
}
// submit was pressed
}
way 3 (through an ActionNameSelectorAttribute
):
https://stackoverflow.com/a/7111222/28004
P.S. No need to specify FormMethod.Post
as that's the default value.