My C# model:

public class MyModel
{
    public string MyString { get; set; }
    public int MyInt { get; set; }
    public List<MyList> MyList { get; set; }
}

public class MyList
{
    public string MyListString { get; set; }
    public int MyListInt { get; set; }
}

My C# method:

[HttpPost]
public void SomeMethod(MyModel MyModel)
{

My AngularJS $http:

$http({
    url: "/api/SomeCtrl/SomeMethod",
    method: "POST",
    data: // WHAT TO PUT HERE?
    headers: { 'Content-Type': 'application/json' }
});

I'm able to fill MyModel with:

data: transportDocumentData.TDShipment,

Or MyList which is present in MyModel with:

data: JSON.stringify({ Package: transportDocumentData.TDShipment.packageData }),

But I don't know how to fill them both. I tried with both options:

$http({
    url: "/api/SomeCtrl/SomeMethod",
    method: "POST",
    data: myModelData.MyModel,
    data: JSON.stringify({ MyList: myModelData.MyModel.myListData }),
    headers: { 'Content-Type': 'application/json' }
});

Which won't work, because the second data overwrites the first one. I also tried this:

var abc = myModelData.MyModel;
$http({
    url: "/api/SomeCtrl/SomeMethod",
    method: "POST",
    data: JSON.stringify({ MyList: myModelData.MyModel.myListData }), abc
    headers: { 'Content-Type': 'application/json' }
});

But in this case only the MyList is filled.

I tried to modify MyMethod like this:

[HttpPost]
public void SomeMethod(List<MyModel> MyModel)
{

With even worse results.

So, how is it done correctly?

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.