Archive for June, 2016

MVC model property marked required when it shouldn’t have been

I had a field in my MVC application that was just your average, ordinary, field:

public int CoasterNumber { get; set; }

When I sent the model to the controller, this field was being flagged as required, even though it didn’t have a [Required] attribute attached to it.

I was able to get around this issue by making the field a nullable int:

public int? CoasterNumber { get; set; }

Leave a comment

The Case of the Different Dates

I ran into an issue in an MVC application where I had two dates in a table. One was being displayed as just a date, and the other included the time component as well. I just wanted the date. The difference was that the property in the model for the time-less date had a DataType attribute and the other date didn’t:


       [DisplayName("Enter Date")]
       public DateTime EnterDate { get; set; }


       [DisplayName("Work Date")]
       public DateTime WorkDate { get; set; }

Adding the attribute fixed the issue.

Leave a comment

Clearing controls with jQuery

A quick method to clear textbox and select controls using jQuery. In this case, I have all my controls inside a Bootstrap “form-inline” class, and that is how I selected them:

function clearControls() {


Leave a comment