我有以下gridview代碼,我正在嘗試對我的日期進行一些基本驗證。正如你可以看到我有一個開始日期和結束日期,我需要驗證它們,以便StartDate < = EndDate。有沒有一種簡單的方法將此驗證添加到下面的代碼中?在MVC Gridview中驗證日期
Html.DevExpress().GridView(settings =>
{
settings.Name = "gvActiveScheduledAnnouncements";
settings.Width = Unit.Percentage(100);
settings.KeyFieldName = "AnnouncementId";
settings.CallbackRouteValues = new { Controller = "Home", Action = "ActiveScheduledAnnouncementsPartial" };
settings.SettingsEditing.Mode = GridViewEditingMode.EditForm;
settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Home", Action = "AddNewAnnouncement" };
settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Home", Action = "UpdateActiveScheduledAnnouncement" };
settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Home", Action = "DeleteActiveScheduledAnnouncement" };
settings.Columns.Add(c =>
{
c.Caption = "Announcement Text";
c.FieldName = "Text";
c.ColumnType = MVCxGridViewColumnType.Memo;
c.EditFormSettings.ColumnSpan = 2;
c.ColumnType = MVCxGridViewColumnType.Memo;
var memo = c.PropertiesEdit as MemoProperties;
memo.Rows = 3;
});
settings.Columns.Add(c =>
{
c.Caption = "Start Date";
c.FieldName = "StartDate";
c.ColumnType = MVCxGridViewColumnType.DateEdit;
});
settings.Columns.Add(c =>
{
c.Caption = "End Date";
c.FieldName = "EndDate";
c.ColumnType = MVCxGridViewColumnType.DateEdit;
});
settings.Columns.Add(c =>
{
c.Caption = "Display Status";
c.FieldName = "DisplayStatus";
c.EditFormSettings.Visible = DefaultBoolean.False;
});
})
.Bind(Model)
.Render();
你想要哪種驗證:客戶端還是服務器端?如果使用服務器端,則在控制器代碼中放置一個if條件,否則使用JS/jQuery和'MVCxClientGridView'方法讀取編輯表單上的日期字段,然後使用if-condition檢查它們的值。 –
老實說,我對兩者都很感興趣,但一直都不知道該怎麼做,所以如果你能提供一個例子,我會很感激。 –