I have a simple setup but cannot figure out why this wont work. Here’s what I have set up:
- MVC4
- Html.EnableUnobtrusiveJavaScript() and
Html.EnableClientValidation() enabled - jQuery 1.6.2,
jquery.validate.min.js, and jquery.validate.unobtrusive.min.js
referenced - No events bound to form or button submit
The problem is, it seems to work on the client side, where I can submit a form and it shows the appropriate validation errors. However, when I then properly fill out the form and hit submit, it does nothing and the last error message I had previously is still displayed. If I go back and clear fields, the validation appears to still be working (validation summary is updated appropriately). If I submit the first time with all fields correctly entered, it works just fine. It’s only if I first have an error that it cannot submit again.
The model only has [Required] on firstname, lastname, and email. No other attributes. Also, FormFieldFor is just a wrapper for EditorFor().
Code below. Any ideas? Thanks.
@model AscendOne.CareOne.Mvc.Models.ResourceGuideUserModel
@*Form*@
<form id="guide-download-submit" method="get" action="/leads/" target="_blank">
@{
Html.EnableUnobtrusiveJavaScript();
Html.EnableClientValidation();
}
@Html.ValidationSummary()
@if (Model.CampaignID != null)
{<input type="hidden" name="CampaignID" value="@Model.CampaignID" />}
@if (!String.IsNullOrWhiteSpace(Model.PDFUrl))
{<input type="hidden" name="RedirectUrl" value="@Model.PDFUrl" />}
<fieldset>
@Html.FormFieldFor(m => m.FirstName)
@Html.FormFieldFor(m => m.LastName)
@Html.FormFieldFor(m => m.Email)
</fieldset>
<button type="submit">Download The Guide</button>
</form>
public class ResourceGuideUserModel
{
public string CampaignID { get; set; }
public string PDFUrl { get; set; }
[Required]
[DisplayName("First Name:*")]
public string FirstName { get; set; }
[Required]
[DisplayName("Last Name:*")]
public string LastName { get; set; }
[Required]
[DisplayName("Email Address:*")]
public string Email { get; set; }
}
Well, turns out it was my fault. Thanks for the replies. Seems another deeply-buried script was killing my form submit after the 1st try. Removing this resolved the issue. Thanks again though.