I confused after hours because I have an issue about getting null model in my api in a project same as another one that everything is ok in it!

About issue

Javascript:

var data = new FormData(),
    firstName = $('#FirstName').val(),
    lastName = $('#LastName').val();
data.append("FirstName", firstName);
data.append("LastName", lastName);

        var ajaxRequest = $.ajax({
            type: "POST",
            url: "/api/CRUD/AddPatient",
            contentType: "application/json",
            processData: false,
            data: data,
            success: function (xhr, data) {
                alert(data);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                //handle error
            }
        });

API

    public string AddPatient(PatientBindingModel model)
    {
        try
        {
            PatientStore ps = new PatientStore();

            string ticks = DateTime.Now.Ticks.ToString();

            ps.Register(model);

            return "success";
        }
        catch (Exception ex)
        {
            string exMessage = ex.Message;
            return exMessage;
        }
    }

And the model passed into api controller is null at all!

Anyone have any idea? Thanks

0 Answers 11

Not the answer you're looking for? Browse other questions tagged or ask your own question.