简体   繁体   中英

ASP.NET MVC4 Validation Error - Whats wrong

So I have a validation error being thrown in Firefox and IE, but not chrome.

I'm stuck and don't know where to look to find out what it does not like

My Model

public class Appointment
{
  [Required]
  public string DateString { get; set; }
  ..
}

The page

<link href="~/Content/CSS/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<input class="form-control date datetime" type="text" value="@Model.DateString" name="DateString" data-min-view="2" data-date-format="dd-M-yyyy" id="DateString">
@Html.ValidationMessageFor(m => m.DateString)
<button type="submit" class="btn btn-primary btn-rad" id="" title="Save"><i class="fa fa-save"></i> Save</button>

<script src="~/Content/Scripts/bootstrap-datetimepicker.min.js"></script>
<script src="@Url.Content("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("https://ajax.aspnetcdn.com/ajax/mvc/4.0/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

The browser

(Before submit)

<input class="form-control date datetime" value="04-Feb-2015" id="DateString" name="DateString" data-min-view="2" data-date-format="dd-M-yyyy" type="text">

So when I press submit it will not post as sets the focus back on the text box

<input aria-invalid="true" aria-describedby="DateString-error" class="form-control date datetime input-validation-error" value="04-Feb-2015" id="DateString" name="DateString" data-min-view="2" data-date-format="dd-M-yyyy" type="text">

So how do I figure out whats wrong?

Can you F12 and validate that you are loading the files required to fire the client side validation.

jquery.unobtrusive-ajax.min.js
jquery.validate.min.js
jquery.validate.unobtrusive.min.js

Also you can decorate your model with a required field display annotation and see if the browser will pick that up.

 [Required(ErrorMessage = "*")]
 public string FieldName{ get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM