我有一個部分視圖(如下)的MVC應用程序。當我添加Html.EnableClientValidation()時,我的字段在退出時消失。我不希望任何人從代碼中找出它,但如果有人看到了這樣的行爲,並且可以指引我正確的方向,我會很感激。與此同時,我將開始一塊一塊地重建,看看我能看到什麼,並將回報。EnableClientValidation導致字段消失
謝謝!
<%= Html.ValidationSummary() %>
<% Html.EnableClientValidation(); // IMPORTANT: this line MUST be *before* Html.BeginForm() block %>
<% using (Ajax.BeginForm("Save", "Items", new AjaxOptions { HttpMethod = "post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "ItemPane"})){%>
<%=Html.AntiForgeryToken()%>
<%=Html.Hidden("Item.Id", (ViewData.Model.Item != null) ? ViewData.Model.Item.Id : Guid.Empty)%>
<!--more hidden items elided-->
<table> <!--yes, I know it should be divs-->
<tr>
<td rowspan="2" width="400px">
<div class="formarea">
<fieldset>
<ol>
<li>
<label id="Item_Label"><%= (ViewData.Model != null && ViewData.Model.Item != null) ? String.Format("Item Number {0} v. {1}", ViewData.Model.Item.ItemNumber, ViewData.Model.Item.Iteration) : "New Item" %></label>
</li>
<li>
<label for="Item_Prompt" class="formLabel">Directions:</label>
<%=Html.TextAreaFor(t => t.Item.Directions, 3, 50, new { @class = "text2000", @maxlength = "2000" })%>
<%= Html.ValidationMessageFor(t => t.Item.Directions, "*")%>
</li>
<li>
<label for="Item_Prompt" class="formLabel">Prompt:</label>
<%= Html.TextBoxFor(model => model.Item.Prompt, new { @class = "text200", @maxlength = "200" })%>
<%= Html.ValidationMessageFor(model => model.Item.Prompt, "*")%>
</li>
我有以下腳本引用:
<%= Html.Script("~/Scripts/MicrosoftAjax.debug.js") %>
<%= Html.Script("~/Scripts/MicrosoftMvcAjax.debug.js") %>
<%= Html.Script("~/Scripts/jquery-1.4.2.min.js") %>
<%= Html.Script("~/Scripts/jquery-ui-1.8.2.custom.min.js") %>
<%= Html.Script("~/Scripts/jquery.form.js") %>
<%= Html.Script("~/Scripts/MicrosoftMvcValidation.js") %>
注意的問題:這種情況我是否使用Html.BeginForm()或Ajax.BeginForm() – sydneyos 2010-07-09 00:31:02