gpt4 book ai didi

asp.net-mvc-3 - 客户端数据注释验证不适用于使用 firefox 和 chrome 的部分 View

转载 作者:行者123 更新时间:2023-12-05 01:11:38 41 4
gpt4 key购买 nike

我的 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 部分 View :-@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>

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

最佳答案

我在这个代码块中发现了一个拼写错误。您在 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>

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

关于asp.net-mvc-3 - 客户端数据注释验证不适用于使用 firefox 和 chrome 的部分 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10420281/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com