我在我的應用程序中有一個頁面,我已經使用validate.min.js
和validate.unobtrusive.min.js
來應用MVC客戶端驗證,但它不起作用。驗證在服務器端正常工作,但不在客戶端。我認爲我用於菜單的js可能會造成問題。但我無法理解如何解決它,因爲我使用的菜單需要菜單效果。MVC3客戶端驗證不起作用
任何人如果有任何想法請分享。
代碼視圖頁:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ApricaCRMEvent.Models.User_Detail>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
RegisterUser1
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>RegisterUser1</h2>
<script src="<%: Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
<script src="<%: Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js") %>" type="text/javascript"></script>
<% using (Html.BeginForm()) { %>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>User_Detail</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.Username) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.Username) %>
<%: Html.ValidationMessageFor(model => model.Username) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Password) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.Password) %>
<%: Html.ValidationMessageFor(model => model.Password) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Email_Add) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.Email_Add) %>
<%: Html.ValidationMessageFor(model => model.Email_Add) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Alt_Email_Add) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.Alt_Email_Add) %>
<%: Html.ValidationMessageFor(model => model.Alt_Email_Add) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.ConfirmPassword) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.ConfirmPassword) %>
<%: Html.ValidationMessageFor(model => model.ConfirmPassword) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
它生成的html:
<!DOCTYPE html>
<html>
<head id="Head1"><title>
RegisterUser1
</title><link href="../Content/Site.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="/Scripts/modernizr-1.7.min.js" type="text/javascript"></script>
<!-- for Menu (Imp: jquery.js and menu.js must be included at last in links for menu effects to work.)-->
<link href="../Content/menu.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery.js" type="text/javascript"></script>
<script src="../../Scripts/menu.js" type="text/javascript"></script>
<!--- for menu end -->
</head>
<body>
<div class="page">
<header>
<table id="header">
<tr>
<td>
<div id="aprica_logo">
<img src="../../Content/images/Apricalogo.png" alt="Aprica" style="width: 134px;
height: 100px;" />
</div>
</td>
<td>
<div align="center" id="title">
<h1>
Aprica</h1>
</div>
</td>
<td>
<div id="logindisplay">
Welcome <strong>admin</strong>
[ <a href="/CRMLogin/LogOff">Log Out</a> ]
</div>
</td>
</tr>
</table>
<div id="menu">
<ul class="menu">
<li><a href="#" class="parent"><span>My Account</span></a>
<div>
<ul>
<li><a href="#"><span>Change Password</span></a></li>
<li><a href="#"><span>Message Passing</span></a></li>
<li><a href="#"><span>Edit Profile</span></a></li>
</ul>
</div>
</li>
<li>
<a href="/CRMDashboard/Dashboard">
<span>Dashboard</span></a></li>
<li><a href="/CRM/Index" class="parent"><span>CRM Request</span></a>
<div>
<ul>
<li><a href="/CRM/AddNewCRM"><span>Add New CRM Request</span></a></li>
<li><a href="/CRM/ViewNewlyArrivedCRMRequest"><span>CRM Request List</span></a></li>
<li><a href="/CRM/NewOldDoctor"><span>CRM Doctors List</span></a></li>
<li><a href="/CRM/AddCRMDoctorBudget"><span>Add New CRM Doctor</span></a></li>
<li><a href="/CRM/UpdateCRMDoctorBudgetMain"><span>Edit CRM Doctor</span></a></li>
</ul>
</div>
</li>
<li><a href="#" class="parent"><span>Reports</span></a>
<div>
<ul>
<li><a href="#" class="parent"><span>Chart Reports</span></a>
<div>
<ul>
<li><a href="/ChartReport/Index"><span>CRM Request Reports</span></a>
</li>
</ul>
</div>
</li>
<li><a href="/Report/CRMStatus"><span>CRM Request Status</span></a></li>
<li><a href="/Report/DoctorReport"><span>Doctor wise</span></a></li>
</ul>
</div>
</li>
<li><a href="#" class="parent"><span>Search</span></a>
<div>
<ul>
<li><a href="/Search/CRMIdIndex"><span>CRM Request Id Wise</span></a></li>
<li><a href="/Search/MDLNoIndex"><span>MDLNo Wise</span></a></li>
<li><a href="/Search/TerritoryIndex"><span>Territory Wise</span></a></li>
<li><a href="/Search/RequesterIndex"><span>TBM Wise</span></a></li>
<li><a href="/Search/PriorityIndex"><span>Priority Wise</span></a></li>
<li><a href="/Search/CRMStateIndex"><span>CRM State Wise</span></a></li>
<li><a href="/Search/ServiceStateIndex"><span>Service State Wise</span></a></li>
</ul>
</div>
</li>
<li><a href="/FilterCRMRequest/Index"><span>Filter CRM Requests</span></a></li>
<li><a href="#"><span>Settings</span></a></li>
</ul>
</div>
</header>
<section id="main">
<h2>RegisterUser1</h2>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<form action="/CRMLogin/RegisterUser1" method="post">
<fieldset>
<legend>User_Detail</legend>
<div class="editor-label">
<label for="Username">Username</label>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-required="The Username field is required." id="Username" name="Username" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Username" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Password">Password</label>
</div>
<div class="editor-field">
<input class="text-box single-line password" data-val="true" data-val-required="The Password field is required." id="Password" name="Password" type="password" value="" />
<span class="field-validation-valid" data-valmsg-for="Password" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Email_Add">Email address</label>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-required="The Email address field is required." id="Email_Add" name="Email_Add" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Email_Add" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Alt_Email_Add">Alternate Email address</label>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-required="The Alternate Email address field is required." id="Alt_Email_Add" name="Alt_Email_Add" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Alt_Email_Add" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="ConfirmPassword">Confirm password</label>
</div>
<div class="editor-field">
<input class="text-box single-line password" data-val="true" data-val-equalto="The password and confirmation password do not match." data-val-equalto-other="*.Password" id="ConfirmPassword" name="ConfirmPassword" type="password" value="" />
<span class="field-validation-valid" data-valmsg-for="ConfirmPassword" data-valmsg-replace="true"></span>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
</form>
<footer>
<hr />
<p>
Copyright (c) 2012</p>
<hr />
</footer>
</section>
</div>
</body>
</html>
check in web.config ClientValidationEnabled設置爲true。 – ssilas777
它被設置爲真...我檢查了它 – blue
打開瀏覽器上的控制檯,你使用(打F12)看看是否有任何客戶端異常,因爲我看到你第一次引用jQuery兩次 –