我在aspnet mvc上有一个表单,使用帮助器Ajax.BeginForm,但是当我登顶表单时,我在控制台出现以下错误:
语法错误,无法识别的表达式:标签[for =' [0] .Selected'],标签[for =' [0] .Selected *',# [0] .Selected误差
我的代码是:
@using (Ajax.BeginForm("Save", Model, new AjaxOptions { HttpMethod = "POST");" new { @class = "custom" }))
{
@for (int index = 0; index < Model.Count; index++)
{
<div class="controls">
@Html.HiddenFor(i => i[index].SocialNetworkId)
@Html.CheckBoxFor(i => i[index].Selected)
@Html.DisplayFor(i => i[index].Name, new { @class = "control-label" })
</div>
}
<button type="submit" value="Update" id="btnSave">Save</button>
}
感谢您的帮助。
答案 0 :(得分:0)
请写下面的代码
@using (Ajax.BeginForm("save", Model, new AjaxOptions { HttpMethod = "Post"}, new { @class = "custom" }))
{
@for (int index = 0; index < Model.Count; index++)
{
<div class="controls">
@Html.HiddenFor(i => Model[index].SocialNetworkId)
@Html.CheckBoxFor(i => Model[index].Selected)
@Html.DisplayFor(i => Model[index].Name, new { @class = "control-label" })
</div>
}
<button type="submit" value="Update" id="btnSave">Save</button>
}
您已经在 HttpMethod =“Post”代码附近的ajax中使用了; 符号,这就是问题的原因。