c# - Web.Api Model Binding for [Serializable] class is not working -


this question has answer here:

i have class like;

[serializable]  public class apiclass {             public string userid { get; set; }     public datetime createtime { get; set; }         } 

and in web api controller method like;

    public guid post(apiclass apiclass)     {          // stuff parameter.     } 

when send object json request, reason, if use [serializable] attribute class, not resolved. if remove can values parameter.

what reason?

your model binding should work fine irrespective of serializable attribute, make sure code sends data correct. below code worked fine , without serializable attribute on dto.

$(function() {      var data = { userid : "shyju" };      $.post("api/values", data, function(response) {         document.write(response);     });  }); 

and server code in values controller

public string post(apiclass model) {     return "received" + model.userid; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -