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
-~----------~----~----~----~------~----~------~--~---