環境:Visual Studio的2013和MVC 5不顯眼的客戶端驗證規則必須是唯一的
我升級我的網站從2010年VS & MVC 3 VS 2013 & MVC 5.這只是正常的VS 2010 & MVC 3 ,在升級項目中(VS 2013 & MVC 5),出現以下消息時出錯。
不引人注意的客戶端驗證規則中的驗證類型名稱必須是唯一的。下面的驗證類型被視爲一次以上:日期
類
public partial class FileTransferFilterCriteria
{
public string Fice { get; set; }
public string SourceEmail { get; set; }
public string TargetEmail { get; set; }
public DateTime? FromDate { get; set; }
public DateTime? ToDate { get; set; }
public string Status { get; set; }
public string Category { get; set; }
}
元數據
[MetadataType(typeof(FileTransferFilterCriteria.FileTransferFilterCriteriaMetaData))]
public partial class FileTransferFilterCriteria
{
public class FileTransferFilterCriteriaMetaData
{
[DataType(DataType.DateTime)]
[Date(ErrorMessage = ValidationMessageConstants.InvalidDate)]
[UIHint(UiHintEditorTemplateConstants.DateCalendar)]
[UIHint(UiHintDisplayTemplateConstants.Date)]
public DateTime? FromDate { get; set; }
[DataType(DataType.DateTime)]
[Date(ErrorMessage = ValidationMessageConstants.InvalidDate)]
[UIHint(UiHintEditorTemplateConstants.DateCalendar)]
[UIHint(UiHintDisplayTemplateConstants.Date)]
public DateTime? ToDate { get; set; }
}
}
的Html
<tr>
<th>Upload From Date</th>
<td>
@Html.EditorFor(x => x.Criteria.FromDate, UiHintEditorTemplateConstants.DateCalendar)
@Html.ValidationMessageFor(x => x.Criteria.FromDate)
</td>
</tr>
<tr>
<th>Upload To Date</th>
<td>
@Html.EditorFor(x => x.Criteria.ToDate, UiHintEditorTemplateConstants.DateCalendar)
@Html.ValidationMessageFor(x => x.Criteria.ToDate)
</td>
</tr>
編輯模板
@using System.Globalization
@model DateTime?
@Html.TextBox("",
(Model != null &&
Model.HasValue &&
!Model.Value.ToString(CultureInfo.InvariantCulture).Contains("1900") &&
!Model.Value.ToString(CultureInfo.InvariantCulture).Contains("0001")
?
Model.Value.ToString("MM/dd/yyyy")
:
string.Empty),
new { @class = "datePicker", maxlength = "12", size = "12" })
這裏有什麼問題?
從VS 2010 & MVC 3項目產生的HTML:
<tr>
<th>Upload From Date</th>
<td>
<input class="datePicker" data-val="true" data-val-date="Invalid date specified. Date should be like MM/DD/YYYY." id="Criteria_FromDate" maxlength="12" name="Criteria.FromDate" size="12" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Criteria.FromDate" data-valmsg-replace="true"></span>
</td>
</tr>
<tr>
<th>Upload To Date</th>
<td>
<input class="datePicker" data-val="true" data-val-date="Invalid date specified. Date should be like MM/DD/YYYY." id="Criteria_ToDate" maxlength="12" name="Criteria.ToDate" size="12" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Criteria.ToDate" data-valmsg-replace="true"></span>
</td>
</tr>
生成的HTML - VS 2013和MVC 5,當我拿出日期屬性:
<tr>
<th>Upload From Date</th>
<td>
<input class="datePicker" data-val="true" data-val-date="The field Upload From Date must be a date." id="Criteria_FromDate" maxlength="12" name="Criteria.FromDate" size="12" type="text" value="" />
<br/><span class="field-validation-valid" data-valmsg-for="Criteria.FromDate" data-valmsg-replace="true"></span>
</td>
</tr>
<tr>
<th>Upload To Date</th>
<td>
<input class="datePicker" data-val="true" data-val-date="The field Upload To Date must be a date." id="Criteria_ToDate" maxlength="12" name="Criteria.ToDate" size="12" type="text" value="" />
<br/><span class="field-validation-valid" data-valmsg-for="Criteria.ToDate" data-valmsg-replace="true"></span>
</td>
</tr>
嘗試移除'[數據類型(DataType.DateTime)]'。 –
是的,這就是我發現的錯誤...謝謝 –
仍然有一個問題,如下所述。 –