Creating C1 MVC Controls

Every MVC control is associated with an HTML element that hosts it on the page. There are three ways to create a control:

  • Add the control htmlhelper in the view directly.
  • Start by adding a div element to the view, then add the control htmlhelper to bind it.
  • Start by adding a div element to the view, then use JavaScript code to instantiate the control and bind it to the host element.

This is a FlexGrid created using the first method:

ID
Start
End
Country
Product
Color
Amount
Amount2
Discount
Active
1
1/25/2025
1/25/2025
German
Gadget
Green
$581.61
$1,030.17
14%
2
2/25/2025
2/25/2025
Canada
Gadget
Green
$4,919.02
$163.13
17%
3
3/25/2025
3/25/2025
Japan
Gadget
Red
$2,159.73
$594.79
7%
4
4/25/2025
4/25/2025
German
Gadget
Red
$1,248.66
$1,092.03
22%
5
5/25/2025
5/25/2025
German
Gadget
Black
$4,051.76
$945.62
12%
6
6/25/2025
6/25/2025
Canada
Gadget
Black
($3,131.28)
$342.59
16%
7
7/25/2025
7/25/2025
China
Widget
Red
$698.62
$1,127.02
15%
8
8/25/2025
8/25/2025
US
Widget
White
$3,464.15
$3,065.79
3%
9
9/25/2025
9/25/2025
Korea
Gadget
Black
($2,363.16)
$4,212.80
14%
10
10/25/2025
10/25/2025
US
Widget
White
($2,836.94)
$358.45
6%
11
11/25/2025
11/25/2025
France
Widget
Green
$877.93
$3,861.01
8%
12
12/25/2025
12/25/2025
Korea
Widget
Red
($3,788.14)
$974.55
12%
13
1/25/2025
1/25/2025
German
Gadget
Red
($2,446.92)
$1,324.17
12%
14
2/25/2025
2/25/2025
German
Widget
Black
($4,374.97)
$550.31
18%
15
3/25/2025
3/25/2025
Japan
Gadget
Green
$1,089.32
$448.52
16%
16
4/25/2025
4/25/2025
China
Gadget
Black
$1,341.85
$2,766.17
8%
17
5/25/2025
5/25/2025
US
Widget
Black
$3,596.33
$2,811.90
18%
18
6/25/2025
6/25/2025
China
Widget
Green
$3,232.11
$2,652.60
24%
19
7/25/2025
7/25/2025
France
Gadget
Green
($2,008.99)
$3,402.55
9%
20
8/25/2025
8/25/2025
France
Gadget
White
$2,568.01
$3,944.69
3%
21
9/25/2025
9/25/2025
UK
Widget
Black
($3,476.95)
$4,926.25
1%
22
10/25/2025
10/25/2025
UK
Widget
Red
$2,290.56
$4,147.52
6%
23
11/25/2025
11/25/2025
Japan
Gadget
White
($4,146.76)
$2,926.53
1%
24
12/25/2025
12/25/2025
Canada
Gadget
Red
$4,917.55
$260.31
14%
25
1/25/2025
1/25/2025
Korea
Gadget
Black
$3,824.28
$3,503.75
8%
26
2/25/2025
2/25/2025
Japan
Gadget
White
($4,257.83)
$1,673.87
23%
27
3/25/2025
3/25/2025
Italy
Gadget
Black
$1,095.08
$3,206.67
20%
28
4/25/2025
4/25/2025
German
Gadget
Green
$1,853.66
$4,962.06
18%
29
5/25/2025
5/25/2025
Italy
Widget
White
$3,708.86
$1,151.46
3%
30
6/25/2025
6/25/2025
Canada
Gadget
Green
($3,447.73)
$4,369.43
10%
31
7/25/2025
7/25/2025
German
Gadget
White
($165.64)
$40.39
4%
32
8/25/2025
8/25/2025
China
Widget
White
$160.62
$3,149.83
8%
33
9/25/2025
9/25/2025
Korea
Widget
Red
($2,575.30)
$1,981.89
17%
34
10/25/2025
10/25/2025
Italy
Widget
Red
$3,288.12
$1,303.79
19%
35
11/25/2025
11/25/2025
Korea
Gadget
Red
($4,563.28)
$3,180.75
2%
36
12/25/2025
12/25/2025
Canada
Widget
White
($4,839.71)
$1,582.49
19%
37
1/25/2025
1/25/2025
US
Gadget
Red
$544.13
$225.88
10%
38
2/25/2025
2/25/2025
Canada
Widget
Red
$538.45
$3,424.11
4%
39
3/25/2025
3/25/2025
Japan
Gadget
Red
$1,493.10
$2,695.60
19%
40
4/25/2025
4/25/2025
US
Widget
Black
($2,838.54)
$4,620.52
14%
41
5/25/2025
5/25/2025
UK
Gadget
Black
($3,175.21)
$1,174.79
18%
42
6/25/2025
6/25/2025
France
Widget
Black
$22.88
$1,294.66
17%
43
7/25/2025
7/25/2025
Korea
Widget
Black
($4,129.88)
$669.69
17%
44
8/25/2025
8/25/2025
Korea
Gadget
Green
$2,170.82
$718.93
14%
45
9/25/2025
9/25/2025
Korea
Gadget
Red
($3,000.98)
$2,380.62
9%
46
10/25/2025
10/25/2025
US
Gadget
Red
$3,374.49
$185.32
23%
47
11/25/2025
11/25/2025
Canada
Widget
Green
($2,103.52)
$69.59
23%
48
12/25/2025
12/25/2025
German
Widget
Red
($2,077.64)
$160.80
6%
49
1/25/2025
1/25/2025
France
Gadget
Green
($748.11)
$3,231.89
14%
50
2/25/2025
2/25/2025
German
Widget
Red
$678.23
$2,547.86
3%

This is a FlexChart created using the second method:

MarchAprilMayOrangesApplesPearsBananasPineapples04

And, this is an InputDate created using the third method:

1
2
3
4
5
6
// This file locates: "Scripts/Lesson/C1Mvc/CreateControls.js".
c1.documentReady(function () {
    var theDate = new wijmo.input.InputDate('#theDate', {
        value: new Date()
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using LearnMvcClient.Models;
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1MvcController : Controller
    {
        // GET: CreateControls
        public ActionResult CreateControls()
        {
            ViewBag.Countries = Countries.GetCountries();
            ViewBag.Sales = Sale.GetData(50);
            ViewBag.FruitSales = Fruit.GetFruitsSales();
            return View();
        }
    }
}
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
<h1>
    @Html.Raw(Resources.C1Mvc.CreateControls_Title)
</h1>
@Html.Raw(Resources.C1Mvc.CreateControls_Description)
 
@Html.Raw(Resources.C1Mvc.CreateControls_FlexGrid)
@(Html.C1().FlexGrid<Sale>()
    .AutoGenerateColumns(false)
    .Id("flexgrid")
    .CssClass("grid")
    .IsReadOnly(true)
    .Bind((IEnumerable<Sale>)ViewBag.Sales)
    .OrderBy("ID")
    .Columns(bl =>
    {
        bl.Add(cb => cb.Binding("ID"));
        bl.Add(cb => cb.Binding("Start"));
        bl.Add(cb => cb.Binding("End"));
        bl.Add(cb => cb.Binding("Country"));
        bl.Add(cb => cb.Binding("Product"));
        bl.Add(cb => cb.Binding("Color"));
        bl.Add(cb => cb.Binding("Amount").Format("c"));
        bl.Add(cb => cb.Binding("Amount2").Format("c"));
        bl.Add(cb => cb.Binding("Discount").Format("p0"));
        bl.Add(cb => cb.Binding("Active"));
    })
)
 
@Html.Raw(Resources.C1Mvc.CreateControls_FlexChart)
<div id="theChart"></div>
@(Html.C1().FlexChart("#theChart")
    .Bind((IEnumerable<Fruit>)ViewBag.FruitSales)
    .BindingX("Name")
    .Series(sers =>
    {
        sers.Add().Binding("MarPrice").Name("March");
        sers.Add().Binding("AprPrice").Name("April");
        sers.Add().Binding("MayPrice").Name("May");
    })
)
 
@Html.Raw(Resources.C1Mvc.CreateControls_InputDate)
<div id="theDate"></div>