0

I've read Phil's article ( http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx ) and still can't figure out how I can take json that looks like what I have below and pass it into my controller. I don't have much control over formatting it so I need to take it like this and get the data out of it.

{
  "Id":"720",
  "SponsorName":"Bay Area Association of Database Developers",
  "ImageURL":"~/Images/Sponsors/baadd.org.jpg",
  "NavigateURL":"http://baadd.org/",
  "HoverOverText":"Bay Area Association of Database Developers",
  "Comment":"xx"
}

enter image description here

3
  • What is the repsonse from the server? I know it's 500 but you should get a stack trace. Commented Aug 4, 2011 at 18:51
  • can you please post code from you controller and the object you accept for your controllers input parameter. The names of the object properties and json properties need to match up exactly. Commented Aug 4, 2011 at 18:52
  • Thanks Mrchief for fixing my format. Commented Aug 4, 2011 at 21:30

1 Answer 1

2
public class SponsorUpdateModel
{
  public int Id {get;set;}
  public string SponsorName {get;set;}
  public string ImageURL {get;set;}
  public string NavigateURL {get;set;}
  public string HoverOverText {get;set;}
  public string Comment {get;set;}
}


public ActionResult Update(SponsorUpdateModel model)
{
}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Jakub, what you suggested worked pefectly! thanks. I also accidentally discovered that if I list out the parameters as follows, it also works. [HttpPost] public JsonResult Update(int id, string comment, string hoverOverText, string imageURL, string navigateURL, string sponsorName, string hasCurrentCodeCampYear) {

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.