farshid
farshid

Reputation: 51

The problem is Binding model is a complex model

Please consider the following code snippet :

    public class BrandDto
{
    public int BrandId { get; set; }
    public string columnName { get; set; }
    public string newValue { get; set; }
}

public class BrandViewModel
{
    public BrandDto BrandDto { get; set; }
    public FileUploadViewModel  FileUploadViewModel { get; set; }
}

View Section :

fnDrawCallback: function() {
            $jq_datatables('#table_brand').editable({
                url: function(params) {
                    var requestData = '';
                    requestData = {
                        BrandId: params.pk,
                        columnName: params.name,
                        newValue: params.value
                    };
                    return $.ajax({
                        type: "POST",
                        data: JSON.stringify(requestData),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        url: '@Url',
                        complete: function(xhr, status) {
                          ....
                        }
                    });
                }
            });

and in Controller :

public ActionResult EditBrand([FromBody]BrandViewModel vm)
    {
       vm.BrandDto   **returnd null** ??!!!
    }

My problem is that vm.BrandDto returns the null value please guide me

Upvotes: 1

Views: 26

Answers (1)

Vince
Vince

Reputation: 979

The data structure you are posting in your Ajax call is not representative of what is expected in your controller, try this:

requestData = {
 BrandDto : {
    BrandId: params.pk,
    columnName: params.name,
    newValue: params.value
 }
};

Upvotes: 1

Related Questions