The model I think you're referring to is at the bottom of the original
message:

    public class CreateDashboardViewModel
    {
        public string Title { get; set; }
    }

the json model being passed in is (You can rip out the jquery-fu and
just put in a string for the title to simplify things.

        var model = {Title: "TheTitle" };
        var json = {model: $.toJSON(model)};

I actually just got it working, I had to rip out the contenttype
specification in the ajax call ("contentType: 'application/json;
charset=utf-8'").  Before I did that the passed in data wasn't
appearing int he Context.Request.Params collection. Any idea why?

I wonder if that'll bite me in the rear in some obscure way...

-jt



On Jan 31, 2:28 pm, Mark Jensen <[email protected]> wrote:
> Hi
>
> maybe you should show us how the model as  well as the the json object
> you try to bind to the model :)
>
> but I think you problem lies here
>
> Inner exception:
> ArgumentNullException
> Message:
> Value cannot be null.
> Parameter name: s
>
> could it be that you are trying to bind null value to a datatype that
> cant be null ?
>
> On Jan 31, 7:55 pm, James Thigpen <[email protected]> wrote:
>
> > I'm having trouble passing a JSON object to my action using the
> > JSONBinder. Binding the JSON info to my model fails spectacularly with
> > the following exception:
>
> > MonoRailException
> > Message:
> > Error building method arguments. Last param analyzed was model with
> > value ''
> > StackTrace:
> >    at
> > Castle.MonoRail.Framework.SmartDispatcherController.BuildMethodArguments
> > (ParameterInfo[] parameters
> > , IRequest request, IDictionary`2 actionArgs)
> >    at Castle.MonoRail.Framework.SmartDispatcherController.InvokeMethod
> > (MethodInfo method, IRequest request
> > , IDictionary`2 extraArgs)
> >    at Castle.MonoRail.Framework.ActionMethodExecutorCompatible.Execute
> > (IEngineContext engineContext,
> >  IController controller, IControllerContext context)
> >    at Castle.MonoRail.Framework.Controller.RunActionAndRenderView()
>
> > Inner exception:
> > ArgumentNullException
> > Message:
> > Value cannot be null.
> > Parameter name: s
> > StackTrace:
> >    at System.IO.StringReader..ctor(String s)
> >    at Newtonsoft.Json.JavaScriptConvert.DeserializeObject(String
> > value, Type type, JsonConverter[] converters
> > )
> >    at Newtonsoft.Json.JavaScriptConvert.DeserializeObject(String
> > value, Type type)
> >    at
> > Castle.MonoRail.Framework.Services.NewtonsoftJSONSerializer.Deserialize
> > (String jsonString, Type
> >  expectedType)
> >    at Castle.MonoRail.Framework.JSONBinderAttribute.Bind
> > (IEngineContext context, IController controller
> > , IControllerContext controllerContext, ParameterInfo parameterInfo)
> >    at
> > Castle.MonoRail.Framework.SmartDispatcherController.BuildMethodArguments
> > (ParameterInfo[] parameters
> > , IRequest request, IDictionary`2 actionArgs)
>
> > This is the javascript initiating the request:
>
> > $(function () {
> >     $("#create-dashboard").click(function (e) {
> >         e.preventDefault();
>
> >         var model = {Title: $("#new-dashboard-title").val() };
> >         var json = {model: $.toJSON(model)};
>
> >         var callback = function (result) {
> >             alert(result);
> >         };
>
> >         $.ajax({type:'POST', url: 'Create.ashx', dataType: 'json',
> > data: json,
> >                 contentType: 'application/json; charset=utf-8',
> >                 success: callback, error: function () { alert
> > ("Grrr."); }});
> >     });
>
> > });
>
> > The action:
>
> >         [return: JSONReturnBinder]
> >         public DashboardCreatedViewModel Create([JSONBinder]
> > CreateDashboardViewModel model)
> >         {
> >             var dashboard = dashboardService.Create(CurrentUser,
> > model.Title);
>
> >             return new DashboardCreatedViewModel(new DashboardSummary
> > (dashboard));
> >         }
>
> > And the CreateDashboardViewModel:
>
> >     public class CreateDashboardViewModel
> >     {
> >         public string Title { get; set; }
> >     }
>
> > The only references I've been able to find to using the JSONBinder
> > have been really old and referenced assemblies which don't exist
> > anymore.  I'm running off a not quite current version of castle trunk.
> > I'm pretty sure my problem lies in my own ignorance, and less in a
> > bug.
>
> > Any help is appreciated.  I apologize for the length of the message as
> > well. My problem sits at that annoying nexus of multiple moving parts.
> > I tried to simplify as much as possible.
>
> > -jt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to