Misbit
Misbit

Reputation: 347

Hijacked Umbraco HttpPost action not firing

I've hijacked the route in Umbraco 7.1 and for some reason my HttpPost is not firing when the submit button is pressed. Any input as to why this is? There is a postback taking place when send is pressed but the when putting a break point in the HttpPost it's never fired.

Here's a snippet of my code, the markup followed by the controller.

@inherits UmbracoViewPage
@{
    Layout = "Layout.cshtml";
}
@using (Html.BeginForm()) {
  @Html.AntiForgeryToken()
   @Html.TextAreaFor(m => m.Message)
        < i n p u t type="submit" value="Send" />    



      @Html.ValidationMessageFor(m => m.Message)
 </div>
}

public ActionResult Index(ManageMessageId? smess)
{
  var errorModel = new ErrorModel();
  ...
 return CurrentTemplate(errorModel);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(ErrorModel model)
{
  if (ModelState.IsValid)
  {
      ...
   }

 return View();
}

Upvotes: 4

Views: 441

Answers (1)

Dan Lister
Dan Lister

Reputation: 2583

Assuming you are using SurfaceControllers, you would want to create your form as follows. Note the change in how you create the form and how the generic and parameter match that of the surface controller:

@using (Html.BeginUmbracoForm<MyController>("Index"))
{
}

Your controller should look something like:

public class MyController : SurfaceController
{
    public ActionResult Index(ManageMessageId? smess)
    {
        var errorModel = new ErrorModel();
        ...
        return CurrentTemplate(errorModel);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Index(ErrorModel model)
    {
        if (ModelState.IsValid)
        {
            ...
        }

        return View();
    }
}

Upvotes: 1

Related Questions