This is similar to: another stack overflow q

I have tried something similar to this question:

var MyItem= { "msg": "hello word!" };

$http.post("/MyController/testPost", MyItem).success(function (data) {
    Alert(ok)
})

Then in MyController:

    public void testPost(MyItem MyItem)
    {

    }

Where MyItem, looks like this:

public class MyItem
{
    public string msg; 
}

I have also tried editing MyItem to be like this:

[System.Runtime.Serialization.DataContractAttribute()]
public class MyItem
{
    [System.Runtime.Serialization.DataMemberAttribute()]
    public string msg; 
}

And I've tried editing the post action to be like this:

[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare)]
public void testPost(MyItem MyItem)
{
}

I'm assuming the attributes are an overkill only needed for WCF, but they are based on this: posting json to WCF stack overflow answer The action in the controller is always hit in all scenarios, but MyItem is always has a null value for msg. Am I missing something? Is there a better way of doing this?

Related posts

Recent Viewed