2011-06-08 46 views
0

我正在更改使用MicrosoftMvcValidation.js等進行客戶端驗證的現有ASP.NET MVC2應用程序。從錨定標記中啓動ASP.NET MVC2客戶端驗證

<h2>Details</h2> 
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script> 
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script> 
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script> 

<% Html.EnableClientValidation(); %> 

<% using (Html.BeginForm("Details", "Add", FormMethod.Post, new { id="addForm" })) 
    { %> 
    <%: Html.ValidationSummary(true) %> 

    <fieldset> 
     <legend>Fields</legend> 

     <div class="editor-label"> 
      <%: Html.LabelFor(model => model.Title) %> 
     </div> 
     <div class="editor-field"> 
      <%: Html.TextBoxFor(model => model.Title) %> 
      <%: Html.ValidationMessageFor(model => model.Title) %> 
     </div> 
    ... 
    <input type="submit" value="Create" /> 

客戶端驗證工作正常和丹迪。

但是,設計師想要將提交按鈕更改爲漂亮的錨定標記。我試圖使用錨的onclick事件即提交表單:

<a class="add-campaign-button-done" onclick="document.getElementById('addForm').submit();"><span></span></a> 

表單提交,但是客戶端驗證不再起作用。

回答