XVal and ViewModel - can this be done?

I add xVal to the NerdDinner application - so far so good, I get client-side validation using jQuery.validate in one line, which is really beautiful. But I can not get xVal to check a complex object. Let's say I have a Dinner object that looks like this:

public class Dinner
{
     [Required]
     public string Title { get; set; }
}

and another container object:

public class DinnerWrapper
{
     public Dinner Dinner { get; set; }
     public string Name { get; set; }
}

If my controller passes Dinnerto the view, I can force xVal to do client-side validation at the end of my form, for example:

<% using (Html.BeginForm())
       { %>
    <fieldset>
        <p>
            <label for="Title">
                Dinner Title:</label>
            <%= Html.TextBox("Title") %>
            <%= Html.ValidationMessage("Title", "*") %>
        </p>
    </fieldset>
    <% } %>
<%=Html.ClientSideValidation<Dinner>()%>

But I can't get it to work when I pass DinnerWrapper. xVal does not perform client-side validation with the following setting:

<% using (Html.BeginForm())
       { %>
    <fieldset>
        <p>
            <label for="Title">
                Dinner Title:</label>
            <%= Html.TextBox("Title", Model.Dinner.Title) %>
            <%= Html.ValidationMessage("Title", "*") %>
        </p>
    </fieldset>
    <% } %>
<%=Html.ClientSideValidation<DinnerWrapper>()%>

Any ideas? So far, I have successfully integrated xVal (and NHaml) into the NerdDinner application, but it seems I got into the checkpoint.

+3
1

, ClientSideValidation - ​​ :

<%=Html.ClientSideValidation<Dinner>()%>
0

Source: https://habr.com/ru/post/1708615/


All Articles