当前位置: 代码迷 >> ASP.NET >> MVC2.0 javaScript不能用么?该怎么处理
  详细解决方案

MVC2.0 javaScript不能用么?该怎么处理

热度:10714   发布时间:2013-02-25 00:00:00.0
MVC2.0 javaScript不能用么?
其他字段都使用了Model层的客户端验证,为什么点击submit以后调用了js的validate()函数,页面却一点反应都没有呢?其他的错误信息却都可以显示!

HTML code
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SourceIndex.Models.User>" %><asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">    Register</asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><script language="javascript" type="text/javascript">    function validate() {        var str1=document.getElementById("Password").innerText;        var str2=document.getElementById("ConfirmPassword").innerText;            if (str1 != str2 ) {                document.GetElementById("ConfirmPassword").style.backgroundColor = 'red';                err.innerHTML = "两次输入的密码不一致,请重新输入";            }        }</script>    <h2>Register</h2>    <%Html.EnableClientValidation(); %>    <% using (Html.BeginForm()) {%>        <%= Html.ValidationSummary(true) %>        <fieldset>            <legend>Fields</legend>                        <div class="editor-label">                <%= Html.Label("邮箱   *") %>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.Email) %>                <%= Html.ValidationMessageFor(model => model.Email) %>            </div>            <div class="editor-label">                <%= Html.Label("密码   *")%>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.Password) %>                <%= Html.ValidationMessageFor(model => model.Password) %>            </div>                        <div class="editor-label">                <%= Html.Label("确认密码   *")%>            </div>            <div class="editor-field">                <%= Html.TextBox("ConfirmPassword")%><label id="err"></label>            </div>                        <div class="editor-label">                <%= Html.Label("中文名   *")%>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.CnName) %>                <%= Html.ValidationMessageFor(model => model.CnName) %>            </div>                        <div class="editor-label">                <%= Html.Label("英文名") %>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.EnName) %>                <%= Html.ValidationMessageFor(model => model.EnName) %>            </div>            <div class="editor-label">                <%= Html.Label("地址") %>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.Address) %>                <%= Html.ValidationMessageFor(model => model.Address) %>            </div>                        <div class="editor-label">                <%= Html.Label("传真") %>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.Fax) %>                <%= Html.ValidationMessageFor(model => model.Fax) %>            </div>                        <div class="editor-label">                <%= Html.Label("固定电话") %>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.Phone) %>                <%= Html.ValidationMessageFor(model => model.Phone) %>            </div>                        <div class="editor-label">                <%= Html.Label("手机号") %>            </div>            <div class="editor-field">                <%= Html.TextBoxFor(model => model.Tel) %>                <%= Html.ValidationMessageFor(model => model.Tel) %>            </div>                        <p>                <input id="submit" onclick="validate()" type="submit" value="提交" />            </p>        </fieldset>    <% } %>    <div>        <%= Html.ActionLink("Back to List", "Index") %>    </div></asp:Content>
  相关解决方案