0

I am writing a C# application and I'm using Entity and MVC. I have a form in my index view, where the user can set a mininum date and a maximum date to be searched. However the format is MM/dd/YYYY. I want to set it to dd/MM/yyyy.

        <div class="col-md-6">
            <form class="form-horizontal" asp-action="SimpleSearch">
                <fieldset>
                    <legend>Simple Search</legend>
                    <div class="form-group">
                        <label for="minDate" class="col-lg-2 control-label">Mini Date</label>
                        <div class="col-lg-10">
                            <input type="date" name="minDate" asp-format="{0:dd/MM/yyyy}"  class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="maxDate" class="col-lg-2 control-label">Max Date</label>
                        <div class="col-lg-10">
                            <input type="date" name="maxDate" asp-format="{0:dd/MM/yyyy}"  class="form-control" />
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-10 col-lg-offset-2">
                            <button type="submit" class="btn btn-primary">Submit</button>
                        </div>
                    </div>
                </fieldset>
            </form>
        </div>
    </div>

I've tried this comand, but it's not working. The date's format does not change.

   <input type="date" name="minDate" asp-format="{0:dd/MM/yyyy}"  class="form-control" />

2 Answers2

0

Did you try to add the following attributes on your Date property?

[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]

Is a Date type right? And not a DateTime?

ragnar
  • 150
  • 1
  • 6
0

Edit the model which is including the min and max date and set the following attributes :

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
public DateTime MinDate {Get; Set;}

And don't forget to add :

using System.ComponentModel.DataAnnotations;
Voli
  • 27
  • 6