[CLOSED] Assigning store data from javascript not working
Hi i would like to assign the data property of a store from Javascript. But the Code is not working as expected. see code below.
javascript
Code:
var GetDatabaseSettingResponse = function () {
jQuery.ajax(
{
url: "/DatabaseConfiguration/DatabaseConfiguration/GetDatabaseSettingResponse",
traditional: true,
type: 'POST',
contentType: "application/json; charset=utf-8",
success: function (result) {
var resultData = jQuery.parseJSON(result);
if (resultData.error.length == 0) {
Ext.MessageBox.hide();
DatabaseTypesStore.data = resultData.result.DatabaseServerTypes;
}
else {
Ext.MessageBox.hide();
alert(resultData.error);
}
}
});
}
Store
Code:
<ext:Store ID="DatabaseTypesStore" runat="server" >
<Reader>
<ext:JsonReader IDProperty="DatabaseType" Root="data" >
<Fields>
<ext:RecordField Name="DisplayName" />
<ext:RecordField Name="DatabaseType" />
</Fields>
</ext:JsonReader>
</Reader>
<Listeners>
</Listeners>
</ext:Store>
The combo box that consumes the store
Code:
<ext:ComboBox ID="cmbDatabaseType"
runat="server"
FieldLabel="Database type"
AnchorHorizontal="100%" Editable="false"
EmptyText="Select Database Type"
StoreID="DatabaseTypesStore"
DisplayField="DisplayName"
Mode="Local"
ValueField="DatabaseType">
</ext:ComboBox>
the controller code that generate the objects
Code:
public string GetDatabaseSettingResponse()
{
JavaScriptAjaxResult result = new JavaScriptAjaxResult();
DatabaseServerTypesResponse response = new DatabaseServerTypesResponse ();
// initialize the object as you want. the model class is shown below
result.Result = response;
}
the model
Code:
public class DatabaseServerTypesResponse
{
/// <summary>
///
/// </summary>
[DataMember]
[JsonProperty]
public List<DatabaseServerCredentialType> DatabaseServerCredentialTypes { get; set; }
/// <summary>
///
/// </summary>
///
[JsonProperty]
public List<DatabaseServerType> DatabaseServerTypes { get; set; }
/// <summary>
///
/// </summary>
[JsonProperty]
public DatabaseConfigurationSettings DatabaseConfigurationSettings { get; set; }
}
public class DatabaseServerCredentialType
{
/// <summary>
///
/// </summary>
[DataMember]
[JsonProperty]
public DatabaseCredentialType DatabaseCredentialType { get; set; }
/// <summary>
///
/// </summary>
[DataMember]
[JsonProperty]
public String DisplayName { get; set; }
}
public class DatabaseServerType
{
/// <summary>
///
/// </summary>
[DataMember]
[JsonProperty]
public DatabaseTypes DatabaseType { get; set; }
/// <summary>
///
/// </summary>
[DataMember]
[JsonProperty]
public String DisplayName { get; set; }
}
public class JavaScriptAjaxResult
{
public JavaScriptAjaxResult()
{
Error = "";
Exception = "";
}
// the error property. this value is set only when there is an error.
// this parameter is used to check if the execution is successful or not
[JsonPropertyAttribute("error")]
public string Error { get; set; }
// hold the value of the exceprion thrown during the action execution
[JsonPropertyAttribute("exception")]
public string Exception { get; set; }
// hold the result if any.
[JsonPropertyAttribute("result")]
public object Result { get; set; }
// returns the JSON string representation of the class. This method must be called by the controller action that
public string ToJson()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}