So I'm using ExtJs to post JSON for updates and creates to my ASP.NET MVC 2 application. I'm also using the ValidateAntiForgery attribute which only works when a POST is made.
Question is: Can I use model binding in this scenario and if so, how?
Here is an example of what the JSON looks like when I attempt to update a 'Company' entity (the "__RequestVerificationToken" is passed as well including the Anti-Forgery token):
{"data":{"Address":"101 Main St.","Id":15}}
The URL looks like this:
http://www.myapp.com/companies/15
And this is what I have so far that works:
[Transaction]
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Update(int id, FormCollection forms) {
var c = serializer.Deserialize<Company>(forms["data"]);
var companyToUpdate = companyRepo.Get(id);
TransferFormValuesTo(companyToUpdate, c); //Custom method
So given the format of the JSON ... is there a way to restructure the Update action method so I can use UpdateModel<> or TryUpdateModel<> like such ...
[Transaction]
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Update(int id) {
var companyToUpdate = companyRepo.Get(id);
UpdateModel<Company>(companyToUpdate);
Also, sure would be nice if the ValidateAntiForgery attribute wasn't dependent on POSTS so that my ASP.NET MVC urls could be truly restful (e.g utilize HttpPut and HttpDelete attributes).