-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeController.cs
93 lines (85 loc) · 2.64 KB
/
HomeController.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DevExpress.Web.Mvc;
using MVCxGridViewDataBinding.Models;
namespace Q588216.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public List<MyModel> Data {
get {
return Session["data"] as List<MyModel> == null ? (List<MyModel>)(Session["data"] = MyModel.GetModelList()) : Session["data"] as List<MyModel>;
}
}
[ValidateInput(false)]
public ActionResult GridViewPartial()
{
return PartialView("_GridViewPartial",Data);
}
[HttpPost, ValidateInput(false)]
public ActionResult GridViewPartialAddNew(MVCxGridViewDataBinding.Models.MyModel item)
{
ViewData["Item"] = item;
var model = MyModel.GetModelList();
if (ModelState.IsValid)
{
try
{
MyModel.InsertModel(Data, item);
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
ViewData["EditError"] = "Please, correct all errors.";
return PartialView("_GridViewPartial", model);
}
[HttpPost, ValidateInput(false)]
public ActionResult GridViewPartialUpdate(MVCxGridViewDataBinding.Models.MyModel item)
{
ViewData["Item"] = item;
if (ModelState.IsValid)
{
try
{
// Insert here a code to update the item in your model
MyModel.UpdateModel(Data, item);
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
else
ViewData["EditError"] = "Please, correct all errors.";
return PartialView("_GridViewPartial", Data);
}
[HttpPost, ValidateInput(false)]
public ActionResult GridViewPartialDelete(Int32 ModelID)
{
if (ModelID >= 0)
{
try
{
MyModel.DeleteModel(Data, ModelID);
}
catch (Exception e)
{
ViewData["EditError"] = e.Message;
}
}
return PartialView("_GridViewPartial", Data);
}
}
}