Question

I need help resolving a design decision roadblock with a coworker. I hardly esteem his opinions, but love posting questions on Stack Overflow, so here goes :)

Suppose I have the following model:

public class Foo
{
  public DateTime FooDate { get; set; }
}

In my template, I want to create a form to do updates/ inserts to this model, so I have the following code:

@using(Html.BeginForm(...))
{
  ...
  @Html.EditorFor(m => m.FooDate)
  ...
}

When doing an update, this will set the value of the textbox to the existing model's value, which is good. However, when I do this with an empty model for an insert, it sets the textbox to 1/1/0001, which is not good.

It's obvious to me as to why this happens, and the solution seems to be to make FooDate nullable and put a [Required] attribute on it. My coworker doesn't seem to approve of this, since the FooDate property isn't really nullable.

The other option would be to have different form templates for inserts and updates I suppose, but that seems equally as wasteful in other respects.

Has anyone else run into this dilemma? If so, what route did you take to resolve/get around it?

Was it helpful?

Solution

I answered a similar question here. See if that is helpful to you. I think it may solve your issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top