Postback not getting picked up

Jun 14, 2012 at 2:46 PM

Ive got it working apart from posting back properly!

All thats happening is i seem to be getting the GET method called. The post is firing and showing in fiddler but not being picked up by the controller. Any ideas why?

Ive stripped this down to a bare page with nothing but the form etc. so no rogue asp.net webforms forms hanging about and still no joy.

Action and method in the form tag seem fine. Any ideas what is wrong?

 

  <html>
    
    <body>
      
    <h2>Newsletter</h2>
                                                    

<form action="/newsletter" method="post">    <fieldset>

        <legend>Newsletter Sign Up Form</legend>



        <div class="editor-label">

            <label for="Name">Name</label>

        </div>

        <div class="editor-field">

            <input class="text-box single-line" id="Name" name="Name" type="text" value="" />

           
        </div>

        <div class="editor-label">

            <label for="Email">Email Address</label>

        </div>

        <div class="editor-field">

            <input class="text-box single-line" id="Email" name="Email" type="text" value="" />
            
        </div>


        <p>

            <input type="submit" value="Submit" />

        </p>

    </fieldset>

</form>
    </body>
  </html>


 

Jun 14, 2012 at 2:49 PM

And my controller is very simple to test this:

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Devotit.Umbraco.MvcBridge;

namespace UmbracoMVCPOC.Controllers
{
    public class NewsletterController : MvcBridgeController
    {
        [HttpGet]
        public PartialViewResult Index()
        {
            return PartialView();
        }
        [HttpPost]
        public PartialViewResult Index(Models.Newsletter model)
        {
            //if (!ModelState.IsValid)
            //    return PartialView(model);

            return PartialView("Success", model);
        }
    }
}

Jun 14, 2012 at 4:41 PM

Sussed it! I wasn't setting the token parameter - once i put something in this it worked.

Could someone explain what the token is for / how should it be used as its not in the demo etc...? 

Is it of a similar purpose to the [ValidateAntiForgeryToken] attribute?  If so I cant see how a plain text hidden input is going to protect against an XSS attack?

Jun 14, 2012 at 5:10 PM
Edited Jun 14, 2012 at 5:12 PM

Just read the support for parameters thread and looks like i was correct on my assumptions....  

Will have to go and re-test because but it didnt seem to want to output the token with the HTML helper so not sure why it wasn't working from the off!