3

我的 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 脚本{

}

    <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>

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

4

1 回答 1

0

我在这个代码块中发现了一个错字。你在 Json.Encode(item) 之后添加了一个逗号。如果这是最后一项,则不能添加逗号。

<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>

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

于 2012-07-06T12:34:12.603 回答