Quote:Hi All, I am working with a contact us page. Since the client have many branches, each page should be loaded with a unique design. The page has enquiry (contact us)form part and a descriptive part. The form contains controls for getting details from the enquirer. While submiting the form, the controls should be reset to its default values and the descriptive part should not change. I wrote the code for clearing the modelstate in controller. Is there any other way for clearing form controls only. Or shall I use partial View here for the enquiry(contact us) form. Please help me.. My code in Model C# public class CandidateContactUs { public CandidateContactUs() { 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 int _countryID; [Display(Name = "Country")] public int countryID { get { return _countryID; } set { _countryID = value; } } 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 tblBranch _clsBranch; public tblBranch clsBranch { get { return _clsBranch; } set{ _clsBranch = value;}} In View C# @using (Html.BeginForm()) { @Html.ValidationSummary(true); <fieldset> <div class="editor-label"> <label for="unCandidateFirstName"> Name</label> </div> <div class="editor-field"> @Html.EditorFor(model => model.unCandidateFirstName) @Html.ValidationMessageFor(model => model.unCandidateFirstName) </div> <div class="editor-label"> <label for="unCandMobilePhone"> Mobile No</label> </div> <div class="editor-field"> @Html.EditorFor(model => model.unCandMobilePhone) @Html.ValidationMessageFor(model => model.unCandMobilePhone) </div> <div class="editor-label"> <label for="countryID"> Country</label> </div> <div class="editor-field"> @Html.DropDownListFor(model => model.countryID, new SelectList(countryList, "countryID", "country"), new { @id = "drpCountry", @class="input-large" }) @Html.ValidationMessageFor(model => model.countryID) </div> <div class="editor-label"> <label for="stateID"> State</label> </div> <div class="editor-field"> @Html.DropDownListFor(model => model.stateID, Model.statesList, new { @id = "drpState" }) </div> <div class="editor-label"> <label for="provinceID"> Province</label> </div> <div class="editor-field"> @Html.DropDownListFor(model => model.provinceID, Model.provinceList, new { @id = "drpProvince" }) </div> <p> <input type="submit" value="Contact Us" /> </p> </fieldset> } </div> <div> <h3> @Model.clsBranchDetails.tblBranchType.branchType</h3> <ul class="contact-us"> <li>class="fa fa-map-marker"> @Model.clsBranchDetails.branchAddress <br> @Model.clsBranchDetails.branchAddressPIN </p> </li> <li>^__i class="fa fa-phone"> <p> ^__strong>Phone: @Model.clsBranch.tblBranchInCharges.Where(s => s.recordActive == true).Select(p => p.branchInChargePhone).FirstOrDefault(); </p> </li> </ul> </div> In Controller C# [HttpPost] public ActionResult ContactUs(CandidateContactUs candidateContactUs) { SM_WEB.Models.SMWebDefaultConnection objSMWebDefaultConnection = new SMWebDefaultConnection(); objSMWebDefaultConnection.smConn.spUNCandidateContactUs(candidateContactUs.unCandidateFirstName, candidateContactUs.unCandMobilePhone, candidateContactUs.countryID, candidateContactUs.stateID, candidateContactUs.provinceID); objSMWebDefaultConnection.smConn.SaveChanges(); ModelState.Clear(); return View(candidateContactUs); }
public class CandidateContactUs { public CandidateContactUs() { 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 int _countryID; [Display(Name = "Country")] public int countryID { get { return _countryID; } set { _countryID = value; } } 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 tblBranch _clsBranch; public tblBranch clsBranch { get { return _clsBranch; } set{ _clsBranch = value;}}
@using (Html.BeginForm()) { @Html.ValidationSummary(true); <fieldset> <div class="editor-label"> <label for="unCandidateFirstName"> Name</label> </div> <div class="editor-field"> @Html.EditorFor(model => model.unCandidateFirstName) @Html.ValidationMessageFor(model => model.unCandidateFirstName) </div> <div class="editor-label"> <label for="unCandMobilePhone"> Mobile No</label> </div> <div class="editor-field"> @Html.EditorFor(model => model.unCandMobilePhone) @Html.ValidationMessageFor(model => model.unCandMobilePhone) </div> <div class="editor-label"> <label for="countryID"> Country</label> </div> <div class="editor-field"> @Html.DropDownListFor(model => model.countryID, new SelectList(countryList, "countryID", "country"), new { @id = "drpCountry", @class="input-large" }) @Html.ValidationMessageFor(model => model.countryID) </div> <div class="editor-label"> <label for="stateID"> State</label> </div> <div class="editor-field"> @Html.DropDownListFor(model => model.stateID, Model.statesList, new { @id = "drpState" }) </div> <div class="editor-label"> <label for="provinceID"> Province</label> </div> <div class="editor-field"> @Html.DropDownListFor(model => model.provinceID, Model.provinceList, new { @id = "drpProvince" }) </div> <p> <input type="submit" value="Contact Us" /> </p> </fieldset> } </div> <div> <h3> @Model.clsBranchDetails.tblBranchType.branchType</h3> <ul class="contact-us"> <li>class="fa fa-map-marker"> @Model.clsBranchDetails.branchAddress <br> @Model.clsBranchDetails.branchAddressPIN </p> </li> <li>^__i class="fa fa-phone"> <p> ^__strong>Phone: @Model.clsBranch.tblBranchInCharges.Where(s => s.recordActive == true).Select(p => p.branchInChargePhone).FirstOrDefault(); </p> </li> </ul> </div>
[HttpPost] public ActionResult ContactUs(CandidateContactUs candidateContactUs) { SM_WEB.Models.SMWebDefaultConnection objSMWebDefaultConnection = new SMWebDefaultConnection(); objSMWebDefaultConnection.smConn.spUNCandidateContactUs(candidateContactUs.unCandidateFirstName, candidateContactUs.unCandMobilePhone, candidateContactUs.countryID, candidateContactUs.stateID, candidateContactUs.provinceID); objSMWebDefaultConnection.smConn.SaveChanges(); ModelState.Clear(); return View(candidateContactUs); }
CandidateContactUs
ModelState.Clear()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)