This question is locked. New answers and comments are not allowed.
Hi,
I have a Telerik.Grid bound to a view model (using Ajax Databinding) and I'm popping up a window (by setting the editable.Mode(GridEditMode.PopUp)). I'm using Html.EditorFor() to pop up the window and it pops up just fine. I can fetch and persist with no problems. All is good...except how I need to display field violations based on the DataAnnotations in my view model.
I'm using the Object.ascx that Brad Wilson explained here. Mine's a bit different in that I don't force the requirement on boolean types and I am using an Html.ValidationSummary(...) instead of the field level violation display Html.ValidationMessage(...). Here's my version:
I've tried several different things. From setting the Html.ValidationSummary(excludePropertyErrors, ...) to true and false to excluding the Html.ValidationMessage(...) all together. No change.
Here's my Controller Action
The validation catches my violations correctly. But the return View(new GridModel<InventoryCategory> {...}); returns and closes the popup and doesn't allow the validation summary to display. This, I'm guessing, is the underlying issue.
Is it possible to show all field violations in a ValidationSummary and not at the field level?
Thanks in advance!
-Mark
I have a Telerik.Grid bound to a view model (using Ajax Databinding) and I'm popping up a window (by setting the editable.Mode(GridEditMode.PopUp)). I'm using Html.EditorFor() to pop up the window and it pops up just fine. I can fetch and persist with no problems. All is good...except how I need to display field violations based on the DataAnnotations in my view model.
I'm using the Object.ascx that Brad Wilson explained here. Mine's a bit different in that I don't force the requirement on boolean types and I am using an Html.ValidationSummary(...) instead of the field level violation display Html.ValidationMessage(...). Here's my version:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> <%= Html.ValidationSummary(false, "Errors") %> <% if (ViewData.TemplateInfo.TemplateDepth > 1) { %> <%= ViewData.ModelMetadata.SimpleDisplayText %> <% } else { %> <table cellpadding="0" cellspacing="0" border="0"> <% foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !ViewData.TemplateInfo.Visited(pm))) { %> <% if (prop.HideSurroundingHtml) { %> <%= Html.Editor(prop.PropertyName) %> <% } else { %> <tr> <td style="padding-top: 5px; padding-right:0px; padding-left:5px; padding-bottom:0px;"> <div class="editor-label" style="text-align:right;"> <span style="font-weight:bold; font-size:14px; color:Red;"><%= (prop.IsRequired && prop.ModelType.Name.ToLower() != "boolean")? "*": "" %></span> <%= Html.Label(prop.PropertyName) %> </div> </td> <td style="padding-top: 5px; padding-right:5px; padding-left:5px; padding-bottom:0px;"> <div class="editor-field"> <%= Html.Editor(prop.PropertyName) %> <% if (prop.IsRequired && prop.ModelType.Name.ToLower() != "boolean") { %> <br /><%= Html.ValidationMessage(prop.PropertyName, "*")%> <% } %> </div> </td> </tr> <% } %> <% } %> </table> <% } %>I've tried several different things. From setting the Html.ValidationSummary(excludePropertyErrors, ...) to true and false to excluding the Html.ValidationMessage(...) all together. No change.
Here's my Controller Action
[Authorize] [GridAction] [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save(InventoryCategory inventoryCategory) { if (inventoryCategory != null && ModelState.IsValid) InventoryCategoryRepository.Save(inventoryCategory); // GenericList<InventoryCategory> inventoryCategoryList = GenericList<InventoryCategory>.GetList("GetInventoryCategoryList", base.ConnectionStringReplacementList); // return View(new GridModel<InventoryCategory> { Data = inventoryCategoryList.List }); } The validation catches my violations correctly. But the return View(new GridModel<InventoryCategory> {...}); returns and closes the popup and doesn't allow the validation summary to display. This, I'm guessing, is the underlying issue.
Is it possible to show all field violations in a ValidationSummary and not at the field level?
Thanks in advance!
-Mark