Skip to content

Commit 8828a7f

Browse files
DevExpressExampleBotDevExpressExampleBot
authored andcommitted
README auto update [skip ci]
1 parent 97d0d6d commit 8828a7f

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

Readme.md

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128552755/24.2.1%2B)
3-
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E3338)
4-
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
5-
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
6-
<!-- default badges end -->
7-
8-
# ASP.NET MVC - How to pass complex objects to a callback Action as callback arguments
9-
10-
This example demonstrates how to convert custom types to a JSON string on the client and parse this string on the server.
11-
12-
The conversion is performed using the `$.toJSON` function that is declared in the [jquery.json-2.2.min](https://github.com/krinkle/jquery-json) file.
13-
14-
```jscript
15-
function GetSerializationData() {
16-
var editorsNames = ["Name", "Age", "Email", "ArrivalDate"];
17-
var editorsValues = {};
18-
for (var i = 0; i < editorsNames.length; i++) {
19-
var control = ASPxClientControl.GetControlCollection().GetByName(editorsNames[i]);
20-
editorsValues[control.name] = control.GetValue();
21-
}
22-
return $.toJSON(editorsValues);
23-
}
24-
```
25-
26-
The `JavaScriptSerializer.Deserialize` method parses the JSON string in a Controller's Action.
27-
28-
```csharp
29-
MyData GetSerializationObject() {
30-
string jsonText = Request.Params["SerializationData"];
31-
if (string.IsNullOrEmpty(jsonText))
32-
return null;
33-
MyData data = null;
34-
try {
35-
data = new JavaScriptSerializer().Deserialize<MyData>(jsonText);
36-
} catch {
37-
ViewData["ErrorMessage"] = "Incorrect data";
38-
}
39-
return data;
40-
}
41-
```
42-
43-
In this example, if it is not possible to deserialize user input, an exception is thrown.
44-
45-
## Files to Review
46-
47-
* [HomeController.cs](./CS/DevExpress.Razor/Controllers/HomeController.cs)
48-
* [CallbackPanelPartial.cshtml](./CS/DevExpress.Razor/Views/Home/CallbackPanelPartial.cshtml)
49-
* [EditorsPartial.cshtml](./CS/DevExpress.Razor/Views/Home/EditorsPartial.cshtml)
50-
* [Index.cshtml](./CS/DevExpress.Razor/Views/Home/Index.cshtml)
51-
<!-- feedback -->
52-
## Does this example address your development requirements/objectives?
53-
54-
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-mvc-convert-custom-types-to-from-json&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-mvc-convert-custom-types-to-from-json&~~~was_helpful=no)
55-
56-
(you will be redirected to DevExpress.com to submit your response)
57-
<!-- feedback end -->
1+
<!-- default badges list -->
2+
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128552755/24.2.1%2B)
3+
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E3338)
4+
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
5+
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
6+
<!-- default badges end -->
7+
8+
# ASP.NET MVC - How to pass complex objects to a callback Action as callback arguments
9+
10+
This example demonstrates how to convert custom types to a JSON string on the client and parse this string on the server.
11+
12+
The conversion is performed using the `$.toJSON` function that is declared in the [jquery.json-2.2.min](https://github.com/krinkle/jquery-json) file.
13+
14+
```jscript
15+
function GetSerializationData() {
16+
var editorsNames = ["Name", "Age", "Email", "ArrivalDate"];
17+
var editorsValues = {};
18+
for (var i = 0; i < editorsNames.length; i++) {
19+
var control = ASPxClientControl.GetControlCollection().GetByName(editorsNames[i]);
20+
editorsValues[control.name] = control.GetValue();
21+
}
22+
return $.toJSON(editorsValues);
23+
}
24+
```
25+
26+
The `JavaScriptSerializer.Deserialize` method parses the JSON string in a Controller's Action.
27+
28+
```csharp
29+
MyData GetSerializationObject() {
30+
string jsonText = Request.Params["SerializationData"];
31+
if (string.IsNullOrEmpty(jsonText))
32+
return null;
33+
MyData data = null;
34+
try {
35+
data = new JavaScriptSerializer().Deserialize<MyData>(jsonText);
36+
} catch {
37+
ViewData["ErrorMessage"] = "Incorrect data";
38+
}
39+
return data;
40+
}
41+
```
42+
43+
In this example, if it is not possible to deserialize user input, an exception is thrown.
44+
45+
## Files to Review
46+
47+
* [HomeController.cs](./CS/DevExpress.Razor/Controllers/HomeController.cs)
48+
* [CallbackPanelPartial.cshtml](./CS/DevExpress.Razor/Views/Home/CallbackPanelPartial.cshtml)
49+
* [EditorsPartial.cshtml](./CS/DevExpress.Razor/Views/Home/EditorsPartial.cshtml)
50+
* [Index.cshtml](./CS/DevExpress.Razor/Views/Home/Index.cshtml)
51+
<!-- feedback -->
52+
## Does this example address your development requirements/objectives?
53+
54+
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-mvc-convert-custom-types-to-from-json&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=asp-net-mvc-convert-custom-types-to-from-json&~~~was_helpful=no)
55+
56+
(you will be redirected to DevExpress.com to submit your response)
57+
<!-- feedback end -->

0 commit comments

Comments
 (0)