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

possible bug using editor templates that contain RenderPartial command

2 Answers 64 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ymris
Top achievements
Rank 1
Ymris asked on 19 Sep 2010, 09:58 PM
The use of the following template prevents client validatation from running:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% if (ViewData.TemplateInfo.TemplateDepth > 1) { %>
    <%= ViewData.ModelMetadata.SimpleDisplayText %>
<% } else { %>
    <table cellpadding="5" cellspacing="5" 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 {%> <% Html.RenderPartial("~/Areas/Editor/Views/Shared/EditorTemplates/EditorRow.ascx", prop); %> <% }%>
    <% } %>
    </table>
<% } %>

The partial view:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DataAnnotationsModelMetadata>" %>
<tr>
    <td>
        <div class="editor-label" style="text-align: right;">
            <%= Model.IsRequired ? "*" : ""%>
            <%= Html.Label(Model.PropertyName)%>
        </div>
    </td>
    <td>
        <div class="editor-field">
            <%= Html.Editor(Model.PropertyName)%>
            <%= Html.ValidationMessage(Model.PropertyName, "*")%>
        </div>
    </td>
</tr>

It all works fine, if you don't use a partial view like here:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<% 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>
                    <div class="editor-label" style="text-align: right;">
                        <%= prop.IsRequired ? "*" : "" %>
                        <%= Html.Label(prop.PropertyName) %>
                    </div>
                </td>
                <td>
                    <div class="editor-field">
                        <%= Html.Editor(prop.PropertyName) %>
                        <%= Html.ValidationMessage(prop.PropertyName, "*") %>
                    </div>
                </td>
            </tr>
        <% } %>
    <% } %>
    </table>
<% } %>

This is not critical, but would make live much easier for me.
Besides from that, great components!

Kind Regards,
Michael

2 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 20 Sep 2010, 07:52 AM
Hello Michael Sander,

I believe that the aforementioned behavior is expected. MVC client validation relies on some additional javascript values, which are not rendered in this case. Here you can check some threads devoted on the same matter:
http://tpeczek.blogspot.com/2010/04/making-aspnet-mvc-2-client-side.html
http://stackoverflow.com/questions/2892031/mvc2-client-validation-isnt-working-when-getting-form-from-ajax-call

Sincerely yours,
Georgi Krustev
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
Ymris
Top achievements
Rank 1
answered on 20 Sep 2010, 09:59 AM
Sorry, my fault, I didn't know that.

Thanks for your prompt answer!

Kind regards,
Michael
Tags
General Discussions
Asked by
Ymris
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Ymris
Top achievements
Rank 1
Share this question
or