I am working on a survey application by using asp.net mvc, bootstrap, jquery unobtrusive validation. I have a validation problem. My table in my database is as follows. I have 2 nonnullable datetime columns.
CREATE TABLE [dbo].[Surveys] (
[SurveyId] INT IDENTITY (1, 1) NOT NULL,
[SurveyName] VARCHAR (50) NOT NULL,
[SurveyDescription] VARCHAR (50) NULL,
[CreatedDate] DATETIME NOT NULL,
[UpdatedDate] DATETIME NOT NULL,
[CreatedUserId] INT DEFAULT ((0)) NOT NULL,
[IsActive] BIT DEFAULT ((0)) NOT NULL,
[Status] BIT DEFAULT ((0)) NOT NULL,
CONSTRAINT [PK__Surveys__A5481F7DFAE1437E] PRIMARY KEY CLUSTERED ([SurveyId] ASC)
);
There is a survey table on the survey display page. When I press the update button on each row in this table, I open a popup. In this popup, only the survey name and survey description can be updated. Validation should only be done for these two areas. Date fields are for informational purposes only and are disabled. The problem is this; When you press submit button for update, jquery unobtrusive tries to validate the disabled date fields. This is not desirable. How do I solve this problem?
As you can see, when you press submit button, a red frame is formed around the date field.
Surveys.cs
// <auto-generated>
using System.ComponentModel.DataAnnotations;
namespace MerinosSurvey.Models
{
using System;
using System.Collections.Generic;
public partial class Surveys
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Surveys()
{
this.SurveyQuestions = new HashSet<SurveyQuestions>();
this.SurveyCustomers = new HashSet<SurveyCustomers>();
}
public int SurveyId { get; set; }
[Required(ErrorMessage = "Lütfen anket adını giriniz.")]
public string SurveyName { get; set; }
[Required(ErrorMessage = "Lütfen anket açıklamasını giriniz.")]
public string SurveyDescription { get; set; }
// [DataType(DataType.Date)]
public System.DateTime? CreatedDate { get; set; }
//[DataType(DataType.Date)]
public System.DateTime? UpdatedDate { get; set; }
public int CreatedUserId { get; set; }
public bool IsActive { get; set; }
public bool Status { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SurveyQuestions> SurveyQuestions { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SurveyCustomers> SurveyCustomers { get; set; }
}
}
AddOrEdit.cshtml (popup)
.
.
.
<div class="form-group row">
@Html.Label("CreatedDate", "Created Date", new { @class = "col-form-label col-md-3" })
<div class="col-md-9">
@Html.TextBoxFor(model => model.CreatedDate, "{0:dd/MM/yyyy}",new { @class = "form-control", type = "date-picker", value = Model.CreatedDate } )
</div>
</div>
<div class="form-group row">
@Html.Label("UpdatedDate", "Updated Date", new { @class = "col-form-label col-md-3" })
<div class="col-md-9">
@Html.TextBoxFor(model => model.UpdatedDate, "{0:dd/MM/yyyy}", new { @class = "form-control", type = "date-picker", value = Model.UpdatedDate })
</div>
</div>
.
.
.