日期:2014-05-18  浏览次数:20371 次

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) %>
                <%=