Fix for Date and Int datatypes having new editors in MVC4
This commit is contained in:
@@ -86,7 +86,7 @@ namespace MileageTraker.Web.Controllers
|
||||
LogType = logType,
|
||||
EmployeeName = name,
|
||||
VehicleId = vehicleId,
|
||||
Date = DateTime.Today.ToShortDateString()
|
||||
Date = DateTime.Today
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ namespace MileageTraker.Web.ViewModels
|
||||
{
|
||||
Mapper.Map(createLogViewModel, this);
|
||||
|
||||
DateHowLongAgo = (DateTime.Today - DateTime.Parse(Date)).ToVerboseStringHistoric();
|
||||
DateHowLongAgo = (DateTime.Today - Date).ToVerboseStringHistoric();
|
||||
|
||||
var dataService = new DataService();
|
||||
|
||||
var endOdometer = int.Parse(createLogViewModel.EndOdometer);
|
||||
var date = DateTime.Parse(createLogViewModel.Date);
|
||||
var date = createLogViewModel.Date;
|
||||
|
||||
var previousLog = dataService.SearchPreviousLog(endOdometer, createLogViewModel.VehicleId, date, DateTime.Now);
|
||||
if (previousLog != null)
|
||||
|
||||
@@ -54,14 +54,12 @@ namespace MileageTraker.Web.ViewModels
|
||||
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[DataType(DataType.Date)]
|
||||
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
|
||||
[RegularExpression(@"([1-9]|0[1-9]|1[012])[- /.]?([1-9]|0[1-9]|[12][0-9]|3[01])[- /.]?20\d{2}",
|
||||
ErrorMessage = "Format is mm/dd/yyyy")]
|
||||
[DisplayFormat(DataFormatString = @"{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
|
||||
[DenyFutureDate(ErrorMessage = "Future date")]
|
||||
[DenyPreviousMonthDate(ErrorMessage = "Previous Month")]
|
||||
[FormatHint("mm/dd/yyyy")]
|
||||
[InputSize("small")]
|
||||
public string Date { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
static CreateLogViewModel()
|
||||
{
|
||||
@@ -102,7 +100,7 @@ namespace MileageTraker.Web.ViewModels
|
||||
try
|
||||
{
|
||||
var dataService = new DataService();
|
||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), DateTime.Parse(Date));
|
||||
dataService.ValidateOdometerChronology(VehicleId, int.Parse(EndOdometer), Date);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
@Html.DisplayNameFor(m => m.Date)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayTextFor(m => m.Date)
|
||||
@Html.Encode(Model.Date.ToShortDateString())
|
||||
<small class="muted">(@Html.DisplayTextFor(m => m.DateHowLongAgo))</small>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
<p>
|
||||
You've successfully created an entry
|
||||
for <strong>@Html.DisplayTextFor(m => m.EmployeeName)</strong>
|
||||
traveling to <strong>@Html.DisplayTextFor(m => m.CityName)</strong>
|
||||
on <strong>@Html.DisplayTextFor(m => m.Date)</strong>
|
||||
traveling to <strong>@Html.DisplayTextFor(m => m.CityName)</strong>
|
||||
on <strong>@Html.Encode(Model.Date.ToShortDateString())</strong>
|
||||
in Vehicle Id <strong>@Html.DisplayTextFor(m => m.VehicleId)</strong>
|
||||
</p>
|
||||
<p>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
@model DateTime
|
||||
@{
|
||||
Layout = "~/Views/Shared/DisplayTemplates/_FieldLayout.cshtml";
|
||||
}
|
||||
@Html.Encode(string.Format(ViewData.ModelMetadata.DisplayFormatString, Model))
|
||||
@@ -1,4 +1,11 @@
|
||||
@{
|
||||
Layout = "~/Views/Shared/DisplayTemplates/_FieldLayout.cshtml";
|
||||
}
|
||||
@Html.Encode(Model)
|
||||
@if (Model == null)
|
||||
{
|
||||
@Html.Encode(@ViewData.ModelMetadata.NullDisplayText)
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.Encode(Model)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
@model DateTime
|
||||
@{
|
||||
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
||||
var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"];
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(inputSize))
|
||||
{
|
||||
@Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ), new { @class = inputSize})
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ))
|
||||
}
|
||||
@@ -1,5 +1,13 @@
|
||||
@model DateTime
|
||||
@{
|
||||
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
||||
var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"];
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(inputSize))
|
||||
{
|
||||
@Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ), new { @class = inputSize})
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ))
|
||||
}
|
||||
@Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ))
|
||||
@@ -0,0 +1,12 @@
|
||||
@{
|
||||
Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml";
|
||||
var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"];
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(inputSize))
|
||||
{
|
||||
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = inputSize})
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue)
|
||||
}
|
||||
@@ -227,6 +227,9 @@
|
||||
<Content Include="Views\Web.config" />
|
||||
<Content Include="Views\Log\BackToLogs.cshtml" />
|
||||
<Content Include="Views\Vehicle\BackToVehicles.cshtml" />
|
||||
<Content Include="Views\Shared\EditorTemplates\Date.cshtml" />
|
||||
<Content Include="Views\Shared\DisplayTemplates\Date.cshtml" />
|
||||
<Content Include="Views\Shared\EditorTemplates\Int32.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="packages.config" />
|
||||
|
||||
Reference in New Issue
Block a user