客户端数据注释验证不适用于使用firefox和chrome的部分视图

时间:2012-05-02 19:23:04

标签: asp.net-mvc-3 data-annotations

我在asp.net mvc web应用程序中有以下主视图: -

<table>
        <tr>
        <th>
        Lab Test
        </th>
        <th>
        Result
        </th>
        <th>
        Date Taken
        </th>
        <th>
        Comment
        </th>
        <th>

        </th>
 @for (int item = 0; item < 10; item++)
        {
using (Ajax.BeginForm("CreateAll", "VisitLabResult", new AjaxOptions
{
    HttpMethod = "Post",
    UpdateTargetId = item.ToString(),
    InsertionMode = InsertionMode.Replace,
    OnSuccess = string.Format(
                   "disableform({0})",
                   Json.Encode(item)),
}))
{ <tr id = "@item">
        @Html.Partial("_create",Model)
       </tr>
            }
        } </table>

,呈现以下_create局部视图: - @section scripts {

}

    <td>
        @Html.DropDownList("LabTestID", String.Empty)
        @Html.ValidationMessageFor(model => model.LabTestID)
   </td>
   <td>
        @Html.EditorFor(model => model.Result)
        @Html.ValidationMessageFor(model => model.Result)
    </td>
    <td>
        @Html.EditorFor(model => model.DateTaken)
        @Html.ValidationMessageFor(model => model.DateTaken)
    </td>
    <td>
        @Html.EditorFor(model => model.Comment)
        @Html.ValidationMessageFor(model => model.Comment)

    </td>
    <td>
    <input type= "hidden" name = "visitid" value = "@ViewBag.visitid" />
    <input type="submit" value="Create" />
    </td>

目前所有数据注释客户端验证(例如Required)都不会显示使用firefox或chrome,但它们将使用IE9正常工作,所以可能是什么问题。 BR

1 个答案:

答案 0 :(得分:0)

我在这个代码块中发现了一个拼写错误。你在Json.Encode(item)之后添加了一个komma。如果这是最后一项,则无法添加komma。

<table>
            <tr>
            <th>
            Lab Test
            </th>
            <th>
            Result
            </th>
            <th>
            Date Taken
            </th>
            <th>
            Comment
            </th>
            <th>

            </th>
     @for (int item = 0; item < 10; item++)
     {
         using (Ajax.BeginForm("CreateAll", "VisitLabResult", new AjaxOptions{
                HttpMethod = "Post",
                UpdateTargetId = item.ToString(),
                InsertionMode = InsertionMode.Replace,
                OnSuccess = string.Format("disableform({0})", Json.Encode(item))})
         ){ 
             <tr id = "@item">
                 @Html.Partial("_create",Model)
             </tr>
         }
     } 
</table>

希望这会奏效。让我知道。