-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.cshtml
186 lines (139 loc) · 6.63 KB
/
Index.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<html>
<body>
<div class="container">
<br />
<br />
<div class="row">
<h1 style="color:Blue;">
<marquee>Register your Details!</marquee>
</h1>
</div>
<br />
<div class="row">
<label>ID</label>
<input type="text" class="form-control" id="txtid" placeholder="Enter id" /><br /></div>
<div class= "row">
<label>Name</label>
<input type="text" class="form-control" id="txtname" placeholder="Enter your Name" /><br /></div>
<div class="row">
<label>City</label>
<input type="text" class="form-control" id="txtcity" placeholder="Your current place" /><br /></div>
<div class="row">
<label>Age</label>
<input type="text" class="form-control" id="txtage" placeholder="Your Age" /><br /></div>
<br />
<div class="row">
<button type="button" class="btn btn-primary" id="btnsave">SAVE</button>
<button type="button" class="btn btn-primary" id="btnupdate">UPDATE</button>
<button type="button" class="btn btn-primary" id="btndelete">DELETE</button>
</div>
<br />
<br />
<div>
<p><i>Note:Use id value to update/delete data from the table</i></p>
<table id="grid" class="display" border="1">
<thead>
<tr>
<th>
ID
</th>
<th>
NAME
</th>
<th>
CITY
</th>
<th>
AGE
</th>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>
<script src="../../Scripts/jquery-1.6.2.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="../../Content/bootstrap-3.3.6-dist/js/bootstrap.min.js" type="text/javascript"></script>
<link href="../../Content/bootstrap-3.3.6-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="../../Content/DataTables-1.9.4/media/js/jquery.dataTables.min.js" type="text/javascript"></script>
<link href="../../Content/DataTables-1.9.4/media/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$("#grid").dataTable({
"sAjaxSource": "../Home/grid", //sAjaxSource for loading data from external source contains URL from -
"bDestroy": true, // - which a JSON object can be obtained from.
"aoColumns": [
{ "sName": " " }, //aoColumns (array), the length of this array should be equal to
{ "sName": " " }, // - no.of columns.
{ "sName": " " },
{ "sName": " " },
]
});
//alert("Data table 1");
$("#grid").delegate("tr", "click", function () { //delegate(selector,event,function) of jquery.
var list = $("#grid").DataTable();
var ipos = list.fnGetPosition(this);
if (ipos != null) {
var aData = list.fnGetData(ipos);
var iId0 = aData[0];
var iId1 = aData[1];
var iId2 = aData[2];
var iId3 = aData[3];
$("#txtid").val(iId0);
$("#txtname").val(iId1);
$("#txtcity").val(iId2);
$("#txtage").val(iId3);
}
});
//alert("Data table 2");
$("#btnsave").click(function ()
{
var id = $("#txtid").val();
var name = $("#txtname").val();
var city = $("#txtcity").val();
var age = $("#txtage").val();
alert("Value being passed into controller");
$.ajax({
url: '../Home/Save',
type: 'GET',
data: { id: id, name: name, city: city, age: age },
success: function (data) {
alert("Save successful!");
window.location.href = '../Home/Index';
}
});
});
$("#btnupdate").click(function () {
var id = $("#txtid").val();
var name = $("#txtname").val();
var city = $("#txtcity").val();
var age = $("#txtage").val();
alert("Update data being passed into controller");
$.ajax({
url: '../Home/update',
TYPE: 'POST',
data: { id: id, name: name, city: city, age: age },
success: function (data) {
alert("successfully updated");
window.location.href = "../Home/Index";
}
});
});
$("#btndelete").click(function () {
var id = $("#txtid").val();
alert("Delete data being passed into controller");
// var name = ("#txtnme").val();
// var city = ("#txtpla").val();
$.ajax({
url: '../Home/delete',
TYPE: 'POST',
data: { id: id },
success: function (data) {
alert("successfully deleted");
window.location.href = "../Home/Index";
}
});
});
</script>