This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DevExpressHelpers.cs
44 lines (41 loc) · 1.82 KB
/
DevExpressHelpers.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
using DevExpress.Web.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Mvc;
namespace CustomMVCHelpers.Helpers
{
public static class DevExpressHelpers
{
public static MvcHtmlString GridHelper(this HtmlHelper helper, string name, Type ModelType, string ControllerName)
{
var PropertiesArray = ModelType.GetProperties();
var g = new GridViewSettings()
{ Name = name,
KeyFieldName = PropertiesArray.Where(pr => pr.GetCustomAttributes(typeof(KeyAttribute), true) != null).FirstOrDefault().Name,
CallbackRouteValues = new
{ Controller = ControllerName, Action = name + "Partial" } };
// for demonstration purposes
g.CommandColumn.Visible = false;
g.SettingsEditing.UpdateRowRouteValues = new
{ Controller = ControllerName, Action = name + "UpdatePartial" };
g.SettingsEditing.DeleteRowRouteValues = new
{ Controller = ControllerName, Action = name + "DeletePartial" };
g.SettingsEditing.AddNewRowRouteValues = new
{ Controller = ControllerName, Action = name + "InsertPartial" };
g.Settings.ShowFilterRow = true;
g.Settings.ShowGroupPanel = true;
foreach (var item in PropertiesArray)
{
var c = g.Columns.Add(item.Name);
if (c.FieldName == g.KeyFieldName)
{
c.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
}
}
new GridViewExtension(g, helper.ViewContext).Bind(helper.ViewData.Model).Render();
return MvcHtmlString.Empty;
}
}
}