Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am working with MVC4. I have a problem in my form. I have provided validation checks in my model. But even after filling data to the fields having validation checks, the corresponding action in the controller is not triggering when form is submitted. But triggers when all the fields are filled.

C#
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 type your name")]
        public string unCandidateFirstName { get { return _unCandidateFirstName; } set { _unCandidateFirstName = value; } }

        private string _unCandMobilePhone;
        [Required(ErrorMessage = "Please type your mobile number")]
        public string unCandMobilePhone { get { return _unCandMobilePhone; } set { _unCandMobilePhone = value; } }

        private string _unCandEmail;
        [Required(ErrorMessage = "Please type your email")]
        public string unCandEmail { get { return _unCandEmail; } set { _unCandEmail = value; } }

        private string _unCandLandLine;
        public string unCandLandLine { get { return _unCandLandLine; } set { _unCandLandLine = value; } }

        private int _countryID;
        [Display(Name = "Country")]
        public int countryID { get { return _countryID; } set { _countryID = value; } }
        public SelectList countries { get { return LoadCountries(); } }

        private int _stateID;
        [Display(Name = "State")]
        public int stateID { get { return _stateID; } set { _stateID = value; } }

        private int _provinceID;
        public int provinceID { get { return _provinceID; } set { _provinceID = value; } }

        private string _unCandEnquiry;
        public string unCandEnquiry { get { return _unCandEnquiry; } set { _unCandEnquiry = value; } }

        private Guid _userID;
        public Guid userID { get { return _userID; } set { _userID = value; } }

        private int _referenceId;
        public int referenceId { get { return _referenceId; } set { _referenceId = 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");
        }


Can any body help me..
Posted

1 solution

The Model validation can be done during the Page post back. you need to do the client side validation by using jquery
 
Share this answer
 
Comments
Jineesh TR 12-Nov-14 23:33pm    
I have used annotation for validation checks with jquery unobtrusive validation checks. But even after entering those mandatory fields the action in the controller is not geting triggered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900