-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeController.vb
81 lines (73 loc) · 2.73 KB
/
HomeController.vb
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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.Mvc
Imports DevExpress.Web.Mvc
Imports MVCxGridViewDataBinding.Models
Namespace Q588216.Controllers
Public Class HomeController
Inherits Controller
'
' GET: /Home/
Public Function Index() As ActionResult
Return View()
End Function
Public ReadOnly Property Data() As List(Of MyModel)
Get
Dim l As List(Of MyModel) = TryCast(Session("data"), List(Of MyModel))
If (l Is Nothing) Then
l = MyModel.GetModelList()
Session("data") = l
End If
Return l
End Get
End Property
<ValidateInput(False)> _
Public Function GridViewPartial() As ActionResult
Return PartialView("_GridViewPartial", Data)
End Function
<HttpPost, ValidateInput(False)> _
Public Function GridViewPartialAddNew(ByVal item As MVCxGridViewDataBinding.Models.MyModel) As ActionResult
ViewData("Item") = item
Dim model = MyModel.GetModelList()
If ModelState.IsValid Then
Try
MyModel.InsertModel(Data, item)
Catch e As Exception
ViewData("EditError") = e.Message
End Try
Else
ViewData("EditError") = "Please, correct all errors."
End If
Return PartialView("_GridViewPartial", model)
End Function
<HttpPost, ValidateInput(False)> _
Public Function GridViewPartialUpdate(ByVal item As MVCxGridViewDataBinding.Models.MyModel) As ActionResult
ViewData("Item") = item
If ModelState.IsValid Then
Try
' Insert here a code to update the item in your model
MyModel.UpdateModel(Data, item)
Catch e As Exception
ViewData("EditError") = e.Message
End Try
Else
ViewData("EditError") = "Please, correct all errors."
End If
Return PartialView("_GridViewPartial", Data)
End Function
<HttpPost, ValidateInput(False)> _
Public Function GridViewPartialDelete(ByVal ModelID As Int32) As ActionResult
If ModelID >= 0 Then
Try
MyModel.DeleteModel(Data, ModelID)
Catch e As Exception
ViewData("EditError") = e.Message
End Try
End If
Return PartialView("_GridViewPartial", Data)
End Function
End Class
End Namespace