4

Phil Haack's blog entry describes this process using ASP.NET MVC 2's futures and Crockford's json2.js. John Resig also recommends using Crockford's json2.js in this article regarding "use strict";.

To get this feature today, would you still download the MVC 2 Futures, or is this included in the MVC 2 final, or is this part of the new MVC 3 preview?

Edit:

As Per Jakub's suggestion (and Phil Haack, woot!), my script finally works. A big appreciation to both of them.

<script type="text/javascript">
$(document).ready(function () {

    var myData = {};
    myData.value = '9/14/2010 12:00:00 AM';
    var myJson = JSON.stringify(myData);

    $.ajax({
        type: "POST",
        url: "/AdSketch/GetPrintProducts",
        data: myJson, 
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            alert(result);
        }
    });
});
</script>

The MVC controller code:

public JsonResult GetPrintProducts(string value)
{   // At this point "value" holds "9/14/2010 12:00:00 AM"
    return Json(value);
}

2 Answers 2

3

For MVC2 you need Futures. Get the dll, add reference to it and in Global.asax add (Application_Start):

ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());

Don't know about MVC3 - I'm waiting for an RTM. But I do encourage you to give it a go, as sending JSON up to Actions is a pure bliss ;-)

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

1 Comment

As a comment to Jakub's comment, this is totally built into MVC3 out of the box, and it works fabulous!
2

In MVC 3 there is ValueProviderFactories provided out of the box.

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.