Hi all,
I working with MVC4. I have a problem in my project while saving data.
I have few drop downs, text boxes, date pickers in my view. I have written validation checks for a drop down. But when I press the submit button, the form is not posting, but it stays at one of the drop down (drop down for state) that has no validation check.
But when I enter all the fields in the form, the form is posted.
any one please help me. Please let me know if you need any more data..
My Model
public class ContactUsForm
{
public ContactUsForm()
{
statesList = new SelectList(new List<SelectListItem>(), "stateID", "state");
provinceList = new SelectList(new List<SelectListItem>(), "provinceID", "province");
}
public SelectList statesList { get; set; }
public SelectList provinceList { get; set; }
private string _unCandidateFirstName;
[Required(ErrorMessage = "Please enter name")]
public string unCandidateFirstName { get { return _unCandidateFirstName; } set { _unCandidateFirstName = value; } }
private string _unCandMobilePhone;
[Required(ErrorMessage = "Please enter mobile number")]
[RegularExpression(@"^[0-9]*$", ErrorMessage = "Please enter valid phone number")]
[StringLength(50,ErrorMessage="Phone number must be between 10-50 digits",MinimumLength=10)]
public string unCandMobilePhone { get { return _unCandMobilePhone; } set { _unCandMobilePhone = value; } }
private string _unCandEmail;
[Required(ErrorMessage = "Please enter email")]
[RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage = "Please enter a valid e-mail adress")]
public string unCandEmail { get { return _unCandEmail; } set { _unCandEmail = value; } }
private int _countryID;
[Required(ErrorMessage = "Please select country")]
public int countryID { get { return _countryID; } set { _countryID = value; } }
public SelectList countries { get { return LoadCountries(); } }
private int _stateID;
public int stateID { get { return _stateID; } set { _stateID = value; } }
private SelectList LoadCountries()
{
SM_WEB.Models.SMWebDefaultConnection objSMWebDefaultConnection = new SM_WEB.Models.SMWebDefaultConnection();
var countryList = objSMWebDefaultConnection.smConn.tblCountries.Where(c => c.recordActive == true).Select(c => new { c.countryID, c.country }).ToList();
return new SelectList(countryList, "countryID", "country");
}
}