0

Here are my Classes (Simplified)

public class DailyMenu
{
  public string MenuNoteText { get; set; }
}

public class MenuMonth
{
  public DailyMenu[] DailyMenus { get; set; }
}

And My webApi Action is

[HttpPost]
public void AddMenuItem_New(MenuMonth menuMonth)
{

}

Clientside code for posting data is :

enter image description here

If I check Request.Form[0], I see "sampletext".

in menuMonth, DailyMenus[0] has 1 DailyMenu item... which seems correct.

but this item's MenuNoteText property is null :( I spent more than half day trying to figure this out.. still no results .. I am sure many must have posted a simple javascript object to server.. Can someone tell me what m I missing here ?

1
  • Can you post your client side script? Commented Feb 20, 2013 at 14:59

1 Answer 1

3

From the link:

application/x-www-form-urlencoded: Form data is encoded as name/value pairs, similar to a URI query string. This is the default format for POST.

Seems you forget to tell Web Api that you are sending request in json format, add 3 more headers and stringify your Json:

 contentType: "application/json; charset=utf-8",
 dataType: "json",
 data: JSON.stringify(menuMonth),

Also note that there is one wrong typing: cache, not catche

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.