@(Html.EJ().Grid<Supplier>("FlatGrid") .Datasource(ds=>ds.URL("/Home/DataSource") .InsertURL("/Home/Insert") .UpdateURL("/Home/Update") .RemoveURL("/Home/Delete") .Adaptor(AdaptorType.UrlAdaptor)) . . . .. .Columns(col => { col.Field("Id").HeaderText("Unique ID").IsPrimaryKey(true).Width(75).Add(); . . . }) )
namespace CRUDandValidation.Models { using System.ComponentModel.DataAnnotations;
public class Supplier { [Required(ErrorMessage = "ID is must")] public int Id { get; set; } [RegularExpression(@"^[a-zA-Z0-9 ]{1,10}$")] public string PostalCode { get; set; } [EmailAddress(ErrorMessage = "Invalid email address")] public string EmailAddress { get; set; } [Url] public string WebAddress { get; set; } } |
<div id="Grid"></div> <script type="text/javascript"> $(function () { $("#Grid").ejGrid({ dataSource: ej.DataManager({ url: "/Home/DataSource", insertURL: "/Home/Insert", updateURL: "/Home/Update", removeURL: "/Home/Delete" }), allowPaging: true, . .. . . . columns: [ { field: "Id", isPrimaryKey: true, validationRules: { required: true, messages: { required: "ID is must" }} }, { field: "CompanyName", validationRules: { required: true, minlength: 3 } }, { field: "PostalCode", validationRules: { range: [0, 1000] } } . . . . .
] }); }) |