开发者

can we use JQuery validations in partial view user control in ASP.NET MVC?

开发者 https://www.devze.com 2022-12-20 02:29 出处:网络
I have controls like Textbox, dropdown on my CustomerDetails.ascx partialview. Now can we do JQuery validations on the user controls.

I have controls like Textbox, dropdown on my CustomerDetails.ascx partialview.

Now can we do JQuery validations on the user controls.

In the MainView, we use code like this.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Mvc.Master" 
Inherits="System.Web.Mvc.ViewPage<IEnumerable<DataModel.CustomerMaster>>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="cphHead" runat="server">

    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>

    <script type="text/javascript">
        //JQuery validations
    </script>        
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="server">
    <h2 class="pageName">Custo开发者_如何学Cmer Profile Main View</h2>
</asp:Content>

In the PartialView, we use code like this.

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DataModel.CustomerMaster>" %>
<table>
    <tbody>
        <tr>
            <td class="Form_Label">
                <label for="Zip">Zip</label><em>*</em>
            </td>
            <td CssClass="Form_Value">
                <%= Html.TextBox("AddressDetail.ZipCode", Model.AddressDetail.FirstOrDefault().ZipCode, new { @class = "required zip", minlength = "5"})%>
            </td>
        </tr>

        <tr>
            <td colspan="2" align="center">
                <input type="submit" value="Update" /> 
                <span id="spanUpdateProfile" style="background-color:White;color:Green;font-size:small"></span>
           </td>
        </tr>
    </tbody>
</table>


Yes, you can.

JQuery validation purely work on the client side (html level), so it doesn't matter whether it's on the partial view or full view.


When you think of partial views in mvc, they're probably closer to PHP's include() than to webforms custom controls. So just think of it as plugging in html or javascript/jquery somewhere in the middle of the page :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号