protected override void WriteHtml(HtmlTextWriter writer) { if (!Columns.Any() && AutoGenerateColumns) { foreach (GridColumnBase <T> column in new GridColumnGenerator <T>(this).GetColumns()) { Columns.Add(column); } } var orignalClientValidationEnabled = ViewContext.ClientValidationEnabled; var originalFormContext = ViewContext.FormContext; try { ViewContext.ClientValidationEnabled = true; ViewContext.FormContext = new FormContext { FormId = Name + "form" }; if (Editable.Enabled && IsClientBinding) { InitializeEditors(); } AdjustColumnsTypesFromDynamic(); if (!HtmlAttributes.ContainsKey("id")) { HtmlAttributes["id"] = Id; } var builder = htmlBuilderFactory.CreateBuilder(Scrollable.Enabled); if (DataSource.Type != DataSourceType.Custom || DataSource.CustomType == "aspnetmvc-ajax") { ProcessDataSource(); } if (DataSource.Schema.Model.Id != null) { DataKeys.Add(DataSource.Schema.Model.Id); } var renderingData = CreateRenderingData(); var functionalData = CreateFunctionalData(); var container = builder.CreateGrid(HtmlAttributes, functionalData, renderingData); if (Editable.Mode == GridEditMode.PopUp && (CurrentItemMode == GridItemMode.Insert || CurrentItemMode == GridItemMode.Edit)) { AppendPopupEditor(container, renderingData); } container.WriteTo(writer); if (ViewContext.FormContext != null) { ValidationMetadata.Add("Fields", ProcessValidationMetadata()); ValidationMetadata.Add("FormId", ViewContext.FormContext.FormId); } } finally { ViewContext.FormContext = originalFormContext; ViewContext.ClientValidationEnabled = orignalClientValidationEnabled; } base.WriteHtml(writer); }
protected override void WriteHtml(HtmlTextWriter writer) { if (!Columns.Any() && AutoGenerateColumns) { foreach (GridColumnBase <T> column in new GridColumnGenerator <T>(this).GetColumns()) { Columns.Add(column); } } #if MVC2 || MVC3 var orignalClientValidationEnabled = ViewContext.ClientValidationEnabled; var originalFormContext = ViewContext.FormContext; try { ViewContext.ClientValidationEnabled = true; ViewContext.FormContext = new FormContext { FormId = Name + "form" }; if (Editing.Enabled && IsClientBinding) { InitializeEditors(); } #endif #if MVC3 AdjustColumnsTypesFromDynamic(); #endif RegisterScriptFiles(); if (!HtmlAttributes.ContainsKey("id")) { HtmlAttributes["id"] = Id; } var builder = htmlBuilderFactory.CreateBuilder(Scrolling.Enabled); var renderingData = CreateRenderingData(); var functionalData = CreateFunctionalData(); var container = builder.CreateGrid(HtmlAttributes, functionalData, renderingData); if (Editing.Mode == GridEditMode.PopUp && (CurrentItemMode == GridItemMode.Insert || CurrentItemMode == GridItemMode.Edit)) { AppendPopupEditor(container, renderingData); } container.WriteTo(writer); #if MVC2 || MVC3 if (ViewContext.FormContext != null) { ValidationMetadata.Add("Fields", ProcessValidationMetadata()); ValidationMetadata.Add("FormId", ViewContext.FormContext.FormId); } } finally { ViewContext.FormContext = originalFormContext; ViewContext.ClientValidationEnabled = orignalClientValidationEnabled; } #endif base.WriteHtml(writer); }