HTTPPost not working asp mvc 3

I'm really confused, here is the code:

 [HttpPost]
    public ActionResult Settings(string SubmitButton)
    {
        if (SubmitButton == "Sign In") {
            ServiceLocator.Current.GetInstance<IAppContext>().LoggedUser = null;
            Response.Cookies["loginuser"].Expires = DateTime.Now;
            return RedirectToAction("Logon", "Account");
        }
        if (SubmitButton == "Sign Up") { return RedirectToAction("register", "Account"); }
        if (SubmitButton == "Change Default Ride Settings") { return RedirectToAction("changeSettings", "Home"); }
        return View();
    }

The submission contains

<% using (Html.BeginForm()) {  %>

   Three input ,

<% } %>

the controller does not start with httppost, but starts using httpget

+3
source share
5 answers

You probably need to pass the names of the controllers and actions to Html.BeginForm () in your view. Since the [HttpPost] Settings () action is called for HTTP receive requests, this means that there is no other Settings () action to receive requests, so I assume that your view is served from another action. In this case, you need to explicitly set the controller and action in your Html.BeginForm (). Try the following:

<% using (Html.BeginForm("Settings", "YourControllerName")) { %>
+2
source

html- , , , :

Html.BeginForm("action","controller", FormMethod.Post) { ... }
+2

Index() . , .

0
source

I used ActionName () to solve the same problem,

The code does not work:

[HttpGet]
    public ViewResult RsvpForm()
    {

    [HttpPost]
        public ViewResult RsvpFrom()
        {
        }

Work code:

[HttpGet]
        public ViewResult RsvpForm()
        {
        }
        [HttpPost, ActionName("RsvpForm")]
        public ViewResult RsvpFromPost()
        {
        }
0
source

The right way to use a razor

@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { id = "form1" }))
{
   //form content
}
0
source

All Articles