May 26, 2012, 6:18 PM
Restful Store and SubmitEmptyValue
Hello,
The following code is based on your MVC RESTful example. In the webpage I have:
1) Simple Store:
Why? How can this be fixed?
Thank you very much in advance.
The following code is based on your MVC RESTful example. In the webpage I have:
1) Simple Store:
<ext:Store ID="Store1" runat="server" AutoSave="true" Restful="true">
<Proxy>
<ext:HttpProxy>
<RestAPI CreateUrl="/Customer/Create" ... />
</ext:HttpProxy>
</Proxy>
<Reader>
<ext:JsonReader
IDProperty="id"
Root="data"
MessageProperty="message">
<Fields>
<ext:RecordField Name="id" />
<ext:RecordField Name="email" type="String" SubmitEmptyValue="Null" />
<ext:RecordField Name="lastname" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
2) Simple FormPanel:<ext:FormPanel ID="FormPanel1" runat="server">
<Items>
<ext:TextField ID="EmailField" DataIndex="email" runat="server" FieldLabel="Email" Vtype="email" AllowBlank="true" />
<ext:TextField ID="LastField" DataIndex="lastname" runat="server" FieldLabel="Last" />
</Items>
<Buttons>
<ext:Button ID="Button5" runat="server" Text="Προσθήκη" Icon="Add">
<Listeners>
<Click Handler="if (#{FormPanel1}.getForm().isValid()) #{Store1}.addRecord(#{FormPanel1}.getForm().getFieldValues(false, 'dataIndex'),false, true);" />
</Listeners>
</ext:Button>
</Buttons>
The controller's Create action is the following:[AcceptVerbs(HttpVerbs.Post)]
public RestResult Create(string data)
{
try
{
Customer c = JSON.Deserialize<Customer>(data);
DataContext context = this.DBContext;
context.Owners.InsertOnSubmit(c);
context.SubmitChanges();
return new RestResult
{
Success = true,
Message = "Inserted",
Data = c
};
}
catch (...) { ... }
}
Insertion works fine except empty strings ("") are inserted instead of Null when the form fields are not filled. This happens whether SubmitEmptyValue is set to "Null" (e.g. email field) or not (e.g. Lastname field).Why? How can this be fixed?
Thank you very much in advance.