I have the following code:
@Html.ValidationSummary(false)
@Html.ValidationSummary(true, "xxx")
@using (Ajax.BeginForm(
action,
"Menus",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success
}, new { @id = "menuForm" }))
{
<dl>
<dt>@Html.LabelFor(model => model.Order)</dt>
<dd>@Html.TextBoxFor(model => model.Order)</dd>
<dd>@Html.ValidationMessageFor(model => model.Order)</dd>
</dl>
When I enter an Order value of 999 then I immediately get client side validation that shows me an error message just after the Order Text box. However nothing shows up in the Html.ValidationSummary area. Is it possible to use this with client side validation?
Here is my model:
public class Menu
{
[Range(0, 99, ErrorMessage = "{0} must be between {1} and {2}")]
[DisplayName("Order")]
public int Order { get; set; }
My web config:
<appSettings>
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
I'm not 100% certain but the validation summary I can find in the MVC 3 default application is within the Form. Maybe because your validation summaries are sitting outside of the form they don't get updated. What happens when you move the Validation summary inside the form?
From:
@Html.ValidationSummary(false)
@Html.ValidationSummary(true, "xxx")
@using (Ajax.BeginForm(
action,
"Menus",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success
}, new { @id = "menuForm" }))
{
<dl>
<dt>@Html.LabelFor(model => model.Order)</dt>
<dd>@Html.TextBoxFor(model => model.Order)</dd>
<dd>@Html.ValidationMessageFor(model => model.Order)</dd>
</dl>
To:
@using (Ajax.BeginForm(
action,
"Menus",
null,
new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = success
}, new { @id = "menuForm" }))
{
@Html.ValidationSummary(false)
@Html.ValidationSummary(true, "xxx")
<dl>
<dt>@Html.LabelFor(model => model.Order)</dt>
<dd>@Html.TextBoxFor(model => model.Order)</dd>
<dd>@Html.ValidationMessageFor(model => model.Order)</dd>
</dl>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With