-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUD_UI.cshtml
98 lines (92 loc) · 3.05 KB
/
CRUD_UI.cshtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@model BeyondLogical.Controllers.Booths
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Sony</title>
</head>
<body>
<form id="myform" action="~/Controllers/Home/Sony">
<div style="padding: 40px;">
@{ var adder = 0;}
@foreach (var booth in Model.booths)
{
<div>
Id: <input class="id myclass" id="id_@adder" type="text" value="@booth.id" style="width:40px;" />
</div>
<div>
Name: <input class="name" id="name_@adder" type="text" value="@booth.name" />
</div>
<div>
Detail: <input class="detail" id="detail_@adder" type="text" style="width:100%;" value="@booth.detail" />
</div>
<br />
adder++;
}
<button type="button" onclick="btn()">Update Booths</button>
<script src="~/js/jquery-2.0.3.min.js"></script>
<script>
class myclass {
constructor(id, name, detail) {
this.id = id;
this.name = name;
this.detail = detail;
}
}
function btn() {
var ids = document.querySelectorAll('input[id^="id"]');
var names = document.querySelectorAll('input[id^="name"]');
var details = document.querySelectorAll('input[id^="detail"]');
var myobjecyarray = []
for (var i = 0; i < ids.length; ++i) {
myobjecyarray[i] = new myclass(ids[i].value, names[i].value, details[i].value);
}
// send data to update server
var mydata = { id: "0", name: "Heywood", detail: "my awesome details", mystrings: JSON.stringify(myobjecyarray) };
$.ajax('/api/sony', {
method: 'POST',
data: mydata,
//datatype: 'json',
success: function (data, textStatus, jqXHR) {
alert("API Updated");
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
}
</script>
</div>
</form>
</body>
</html>
<!-- sample JSON
[
{
"id": "1",
"name": "OverWatch",
"detail": "Great online multiplayer game",
"mystrings": null
},
{
"id": "2",
"name": "Fortnite",
"detail": "Another awesome online multiplayer game",
"mystrings": null
},
{
"id": "3",
"name": "FIFA 2018",
"detail": "Online Soccer at it's Best",
"mystrings": null
},
{
"id": "4",
"name": "Uncharted",
"detail": "An Action Packed game developed by Naughty Dog",
"mystrings": null
}
]-->