I have a Model with a list element. I'm creating my page at runtime, with a 'foreach' loop that inserts all list elements in the page. I have also a string value that I want validate (model.trayCapacity) checking if it is NOT null:
[Required(ErrorMessage = "*")]
public string trayCapacity{ get; set; }
public IList<Separatore> SeparatoriLongitudinali{ get; set; }
This is .cshtml code:
@using (Html.BeginForm("Optional", "Config", FormMethod.Post, new { id = "storeDataForm" }))
{
@Html.ValidationSummary(true)
foreach (Separatore sepLong in Model.SeparatoriLongitudinali)
{
@Html.TextBoxFor(x => sepLong.Quantity)
}
<table>
<tr class="webgrid-row-style">
<td>Tray Capacity:</td>
<td>@Html.TextBoxFor(model => model.trayCapacity)</td>
<td>@Html.ValidationMessageFor(model => model.trayCapacity)</td>
</tr>
</table>
<div align="right">
<input type="submit" value="buttonNext" />
</div>
}
There is a SyntaxError: JSON.parse: unexpected character, in jquery.js (version 1.9.1)
, and the page goes on without checking the value.
ValidationSummary works only if I cut off the "foreach" code. Why is that?