This is a migrated thread and some comments may be shown as answers.

[Solved] ValidationSummary when Mode(GridEditMode.PopUp) using Ajax DataBinding

3 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MarkOnDotNet
Top achievements
Rank 2
MarkOnDotNet asked on 27 Sep 2010, 08:04 PM
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:

<%@ 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

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 28 Sep 2010, 08:03 AM
Hi MarkOnDotNet,

 Telerik Grid for ASP.NET MVC is using jquery.validate instead of the built-in ASP.NET Ajax based MVC validation. jquery.validate however does not play nicely with MVC validation summaries and I think this may be the problem. To verify if this is the case I would request a sample project which shows the problem you are experiencing. You can either attach it here or open a support ticket if you don't want to disclose any sensitive data.

Looking forward to your reply,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
MarkOnDotNet
Top achievements
Rank 2
answered on 28 Sep 2010, 08:34 PM
Atanas,

Attached is a zip file with a small sample of what I'm trying to do.  One problem.  In deriving my sample project from my full project (which I thought would be a no brainer) I cannot get the sample to run.

I'm getting a script error.  Apparently some of the Telerik scripts aren't loading and, quite honestly, I'm tired of beating my head against the wall trying to figure out what's missing in regards to the scripts.  The same files in my actual project are in this sample.

Also, to top it off - I have ran into the same problem that I had reported on Support Ticket #349386.  I can get past it, but it's very annoying and I'd like to see if you can determine the underlying issue.  It started happening when I removed the script registrations from the ScriptRegistrar (telerik.common.js and telerik.list.js) in my master page.

If you can get me past the first issue (the script issue), then email me the fixed zip file back I'l finish up the sample project in regards to the ValidationSummary on the popup.

Thanks,
Mark
0
Rosen
Telerik team
answered on 29 Sep 2010, 08:32 AM
Hello MarkOnDotNet,

I have looked at the sample project you have sent us. It seems that the script issue you are facing is due to the fact that the project has reference to an internal build, but has CDN enabled too. As you may know resources from internal builds are not available on our CDN. Therefore, please remove the following lines from the web.config file:

<telerik>
  <webAssets useTelerikContentDeliveryNetwork="true" />
</telerik>

All the best,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
MarkOnDotNet
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
MarkOnDotNet
Top achievements
Rank 2
Rosen
Telerik team
Share this question
or