c# - Why isn't my post method hitting the controller? -


i trying send simple model controller update object. reason evading me.

controller method:

    [authorize(roles = enums.roles.siteadmin)]     [httppost]     [validateantiforgerytoken]     public actionresult edit([bind(include = "buildingid,name")] building building)     {         if (modelstate.isvalid)         {             service.update(building);             return json(new { status = "success!" });         }          return json(new { status = "error." });     } 

ef model:

public class building {     [key()]     public int buildingid { get; set; }      [required()]     [maxlength(200)]     public string name { get; set; }      public virtual icollection<room> rooms { get; set; } } 

javascript post method:

    $('.saveonblur').on('blur', function (e) {         var newbuildingname = $(this).prop("innertext");         var editbuildingid = $(this).siblings('.hiddenid').children().first().val();          var modifiedbuilding = { buildingid: number(editbuildingid), name: newbuildingname };          $.ajax({             url: "/equipment/buildings/edit",             type: 'post',             contenttype: 'application/json',             data: { building: json.stringify(modifiedbuilding) }         });     }) 

i don't know i'm doing wrong. able create objects using similar approach, code doesn't hit controller method, internal error 500 (not 404). ideas?

you have debug. validateantiforgerytoken, if not provide valid value stop before reaches code. not see javascript code includes value in http header.

to trouble-shoot comment out , see if hits method. if not try next filter authorization filter , see if causing code not executed.

if have code handle tokens sent on ajax great, if not there lot of previous questions answers on describe how can creating modified validateantiforgerytokenattribute reads http header.


additional things check.

  1. change data payload data: json.stringify(modifiedbuilding)
  2. check route /equipment/buildings/edit. can provide routing configuration in question make easier.

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -