You are returning "Success" not "success". It is a case sensitive check
Printable View
You are returning "Success" not "success". It is a case sensitive check
Sometimes i add a new method which returnsin a controiller which inherits fromCode:Direct
and the api at DriectApi.ashx never updates?Code:DirectController
is there something i should be doing?
i've restarted the web and all that.
very good implementation however :) - i'm a big fan.
w://
Great tool.
I got it working with the LiveGrid store (based the Bufferstore on the DirectStore).
I wanted to save changed value in the store through a JsonWriter to the update api of the directstore (bufferedstore).
When I saved 1 item, everything was okay. But when I wanted to save more than one changed record from the store I got an array.
JArray was not supported.
I made an implementation but I'm really not sure if it is up to your standard, for me it works in my proof of concept. But it's not yet in production state. So if anyone has any comments, improvements or what ever, feel free.
I created a .patch file (with usage of subversion) against the 0.6.4 version.
Now I can have an update action like this, supporting arrays.Code:Index: DirectMethodInvoker.cs
===================================================================
--- DirectMethodInvoker.cs (revision 4)
+++ DirectMethodInvoker.cs (working copy)
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.Reflection;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -23,10 +24,33 @@
string key = parameterDescriptors[i].ParameterName;
object rawValue = data[i];
- if (rawValue is JObject && parameterDescriptors[i].ParameterType != typeof(JObject)) {
- rawValue = JsonConvert.DeserializeObject(rawValue.ToString(), parameterDescriptors[i].ParameterType);
+ if (rawValue is List<object> && parameterDescriptors[i].ParameterType.BaseType == typeof(Array))
+ {
+ List<object> tempRawArray = rawValue as List<object>;
+ for( int j = 0; j < tempRawArray.Count; j++)
+ {
+ //If is array then get the type of the non array type
+ if (tempRawArray[j] is JObject && parameterDescriptors[i].ParameterType != typeof(JObject))
+ {
+ Assembly assembly = Assembly.GetAssembly(parameterDescriptors[i].ParameterType);
+ Type type = assembly.GetType(parameterDescriptors[i].ParameterType.FullName.Replace("[]",""));
+ tempRawArray[j] = JsonConvert.DeserializeObject(tempRawArray[j].ToString(), type);
+ }
+ }
+ rawValue = tempRawArray.ToArray();
}
+ else if (rawValue is JObject && parameterDescriptors[i].ParameterType != typeof(JObject))
+ {
+ Type type = parameterDescriptors[i].ParameterType;
+ if (type.BaseType == typeof(Array))
+ {
+ Assembly assembly = Assembly.GetAssembly(type);
+ type = assembly.GetType(parameterDescriptors[i].ParameterType.FullName.Replace("[]",""));
+ }
+ rawValue = JsonConvert.DeserializeObject(rawValue.ToString(), type);
+ }
+
string attemptedValue = Convert.ToString(rawValue, invariantCulture);
valueProvider.Add(key, new ValueProviderResult(rawValue, attemptedValue, invariantCulture));
}
Index: RequestDataConverter.cs
===================================================================
--- RequestDataConverter.cs (revision 4)
+++ RequestDataConverter.cs (working copy)
@@ -13,12 +13,34 @@
if (!dataArray.HasValues) return null;
- foreach (JToken dataItem in dataArray) {
- if (dataItem is JObject) {
+ foreach (JToken dataItem in dataArray)
+ {
+ if (dataItem is JObject)
+ {
data.Add(dataItem);
- } else if (dataItem is JValue) {
+ }
+ else if (dataItem is JValue)
+ {
data.Add((dataItem as JValue).Value);
- } else {
+ }
+ else if (dataItem is JArray)
+ {
+ List<object> listObjects = new List<object>();
+ foreach (JToken arrayDataItem in (dataItem as JArray))
+ {
+ if (arrayDataItem is JObject)
+ {
+ listObjects.Add(arrayDataItem);
+ }
+ else if (arrayDataItem is JValue)
+ {
+ listObjects.Add((arrayDataItem as JValue).Value);
+ }
+ }
+ data.Add(listObjects);
+ }
+ else
+ {
throw new ArgumentException("Arguments of this type are not supported.");
}
}
Code:[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update(int[] ids, WebModelContainerStatus[] records)
{
if (Request.IsAjaxRequest())
{
I've got a question.
How to return if the update/ create / etc succeeded or failed?
I tried (in the action-method of the controller):
But don't know how to handle the response in ExtJs.Code:var result = new {
success = false
};
return Direct(result);
maxigroovy
1. I'll take a look at how you implemented arrays later, too busy right now. But thanks!
2. With regard to your second comment, I honestly don't know :) I've never had to do anything like this. Anyhow, it's not directly related to my implementation of Ext.Direct, so you might want to start a new thread in the general Ext.Direct forums.
And ofcourse it's better to use:
instead of the string replacement thing:Code:Type type = parameterDescriptors[i].ParameterType.GetElementType();
For handling the serialization of arrays.Code:Assembly assembly = Assembly.GetAssembly(parameterDescriptors[i].ParameterType);
Type type = assembly.GetType(parameterDescriptors[i].ParameterType.FullName.Replace("[]",""));
Can someone make a rs mirror?I can't download this file.Thks.
Hi!
At first, thanks for your work!
I need some advice or sample of using your implementation with polling provider, of course if you already have something specially for this? Now I'm creating new polling provider and it repetitively makes post requests to the action.