質問編集履歴

3

説明の修正

2020/05/21 10:03

投稿

j-nagnn
j-nagnn

スコア21

test CHANGED
File without changes
test CHANGED
@@ -126,7 +126,7 @@
126
126
 
127
127
  ```
128
128
 
129
- 'json.data'の内容】
129
+ gntの内容】
130
130
 
131
131
  [{"id":1,"text":"project #1","start_date":"2020-05-06","end_date":"2020-05-26","user":3,"duration":20,"parent":0,"progress":0},
132
132
 

2

json.dataの内容をテキストベースに直しました

2020/05/21 10:03

投稿

j-nagnn
j-nagnn

スコア21

test CHANGED
File without changes
test CHANGED
@@ -126,4 +126,10 @@
126
126
 
127
127
  ```
128
128
 
129
- ![イメージ説明](2368a47bf70f8792064640df074af09e.png)
129
+ 【'json.data'の内容】
130
+
131
+ [{"id":1,"text":"project #1","start_date":"2020-05-06","end_date":"2020-05-26","user":3,"duration":20,"parent":0,"progress":0},
132
+
133
+ {"id":2,"text":"Task #1","start_date":"2020-05-06","end_date":"2020-05-16","user":0,"duration":10,"parent":1,"progress":0},
134
+
135
+ {"id":3,"text":"Task #2","start_date":"2020-05-16","end_date":"2020-05-26","user":0,"duration":10,"parent":1,"progress":0}]

1

コード部分を見やすいように変更しました。読み込みたいjsonファイル内容の画像を添付しました。

2020/05/21 09:56

投稿

j-nagnn
j-nagnn

スコア21

test CHANGED
File without changes
test CHANGED
@@ -24,96 +24,106 @@
24
24
 
25
25
  【コード】
26
26
 
27
- [index.cshtml(View)]
27
+ <index.cshtml>
28
28
 
29
- <script type="text/javascript" >
29
+ ```Javascript
30
30
 
31
- function jsonExport() {
31
+ <script type="text/javascript" >
32
32
 
33
- var json = new Object();
33
+ function jsonExport() {
34
34
 
35
- json = gantt.serialize('json');
35
+ var json = new Object();
36
36
 
37
- var gnt = JSON.stringify(json.data);
37
+ json = gantt.serialize('json');
38
38
 
39
- alert(gnt);
39
+ var gnt = JSON.stringify(json.data);
40
40
 
41
+ alert(gnt);
42
+
41
- var aj = '@Url.Action("JSONTest")';
43
+ var aj = '@Url.Action("JSONTest")';
42
44
 
43
45
 
44
46
 
45
-
47
+ $.ajax(
46
48
 
47
- $.ajax(
49
+ {
48
50
 
49
- {
51
+ type: 'POST',
50
52
 
51
- type: 'POST',
53
+ url: aj,
52
54
 
53
- url: aj,
55
+ data: gnt,
54
56
 
55
- data: gnt,
57
+ dataType: 'json',
56
58
 
57
- dataType: 'json',
58
-
59
- contentType: 'application/json',
59
+ contentType: 'application/json',
60
-
61
-
62
-
63
- error: function () { },
64
-
65
- complete: function (data) { alert(data.responseText) }
66
-
67
- }
68
-
69
- );
70
-
71
- }
72
-
73
- </script>
74
60
 
75
61
 
76
62
 
63
+ error: function () { },
64
+
65
+ complete: function (data) { alert(data.responseText) }
66
+
67
+ }
68
+
69
+ );
70
+
71
+ }
72
+
73
+ </script>
74
+
75
+ ```
76
+
77
77
  [HomeControllers.cs]
78
78
 
79
- public ActionResult JSONTest(Data viewModel,Object son)
79
+ ```C#
80
80
 
81
- {
81
+ public ActionResult JSONTest(Data viewModel,Object son)
82
82
 
83
-        string[] vs = new string[4];
83
+ {
84
84
 
85
- vs[0] = viewModel.Text;
85
+ string[] vs = new string[4];
86
86
 
87
- vs[1] = viewModel.StartDate.ToString();
87
+ vs[0] = viewModel.Text;
88
88
 
89
- vs[2] = viewModel.EndDate.ToString();
89
+ vs[1] = viewModel.StartDate.ToString();
90
90
 
91
- vs[3] = viewModel.Duration.ToString();
91
+ vs[2] = viewModel.EndDate.ToString();
92
92
 
93
- return Json(vs);
93
+ vs[3] = viewModel.Duration.ToString();
94
94
 
95
+ return Json(vs);
96
+
95
- }
97
+ }
98
+
99
+ ```
96
100
 
97
101
  [Data.cs(Model)]
102
+
103
+ ```C#
98
104
 
99
105
  namespace GantDHT.Models
100
106
 
101
107
  {
102
108
 
103
- public class Data {
109
+ public class Data {
104
110
 
105
111
 
106
112
 
107
- public int Id { get; set; }
113
+ public int Id { get; set; }
108
114
 
109
- public string Text { get; set; }
115
+ public string Text { get; set; }
110
116
 
111
- public DateTime StartDate { get; set; }
117
+ public DateTime StartDate { get; set; }
112
118
 
113
- public DateTime EndDate { get; set; }
119
+ public DateTime EndDate { get; set; }
114
120
 
115
- public int Duration { get; set; }
121
+ public int Duration { get; set; }
116
122
 
117
- }
123
+ }
118
124
 
119
- }
125
+ }
126
+
127
+ ```
128
+
129
+ ![イメージ説明](2368a47bf70f8792064640df074af09e.png)