@model YourProjectNamespace.Models.Clsprp_Agent @using (Html.BeginForm("RegIndAgent",…
- User
@model YourProjectNamespace.Models.Clsprp_Agent
@using (Html.BeginForm("RegIndAgent", "Agent", FormMethod.Post, new { enctype = "multipart/form-data", id = "agentForm" })) { @Html.AntiForgeryToken()
<div class="border p-3 mb-3"> <h5>Select Option</h5> <div class="form-group"> <label>Do you Already have Delhi RERA Number (Yes/No)? <span class="text-danger">*</span></label> <div> <label class="mr-3"> @Html.RadioButtonFor(m => m.IsAlready_RERANumber, "Yes") Yes </label> <label> @Html.RadioButtonFor(m => m.IsAlready_RERANumber, "No") No </label> </div> @Html.ValidationMessageFor(m => m.IsAlready_RERANumber, "", new { @class = "text-danger" }) </div> </div> <div class="border p-3 mb-3"> <h5>Agent Registration Details</h5> <div class="form-row"> <div class="form-group col-md-4"> @Html.LabelFor(m => m.Agent_FirstName) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.Agent_FirstName, new { @class = "form-control", placeholder = "First Name" }) @Html.ValidationMessageFor(m => m.Agent_FirstName, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.Agent_MiddleName) @Html.TextBoxFor(m => m.Agent_MiddleName, new { @class = "form-control", placeholder = "Middle Name" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.Agent_LastName) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.Agent_LastName, new { @class = "form-control", placeholder = "Last Name" }) @Html.ValidationMessageFor(m => m.Agent_LastName, "", new { @class = "text-danger" }) </div> </div> <div class="form-row"> <div class="form-group col-md-4"> @Html.LabelFor(m => m.Father_FirstName) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.Father_FirstName, new { @class = "form-control", placeholder = "Father's First Name" }) @Html.ValidationMessageFor(m => m.Father_FirstName, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.Father_MiddleName) @Html.TextBoxFor(m => m.Father_MiddleName, new { @class = "form-control", placeholder = "Father's Middle Name" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.Father_LastName) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.Father_LastName, new { @class = "form-control", placeholder = "Father's Last Name" }) @Html.ValidationMessageFor(m => m.Father_LastName, "", new { @class = "text-danger" }) </div> </div> <div class="form-row align-items-end"> <div class="form-group col-md-4"> @Html.LabelFor(m => m.PAN_Number) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.PAN_Number, new { @class = "form-control", placeholder = "PAN Number" }) <small class="text-muted">PAN Number of Real Estate Agent as per PAN Card</small> @Html.ValidationMessageFor(m => m.PAN_Number, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.MobileNumber) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.MobileNumber, new { @class = "form-control", placeholder = "Mobile Number" }) @Html.ValidationMessageFor(m => m.MobileNumber, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.Occupation) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.Occupation, new { @class = "form-control", placeholder = "Occupation" }) @Html.ValidationMessageFor(m => m.Occupation, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label>Do you have other State/UT RERA registration No.(Yes/No)? <span class="text-danger">*</span></label> <div> <label class="mr-3"> @Html.RadioButtonFor(m => m.IsOtherStateUT_RERAregistration, "Yes") Yes </label> <label> @Html.RadioButtonFor(m => m.IsOtherStateUT_RERAregistration, "No") No </label> </div> @Html.ValidationMessageFor(m => m.IsOtherStateUT_RERAregistration, "", new { @class = "text-danger" }) </div> <div class="form-group"> @Html.LabelFor(m => m.EmailAddress) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.EmailAddress, new { @class = "form-control", placeholder = "Email Address" }) @Html.ValidationMessageFor(m => m.EmailAddress, "", new { @class = "text-danger" }) </div> </div> <div class="border p-3 mb-3"> <h5>Upload Photograph of Agent</h5> <div class="form-group"> <label>Upload Photo <span class="text-danger">*</span></label> <input type="file" name="ImageFile" accept=".jpg,.jpeg,.png" class="form-control-file" /> <small class="form-text text-muted">Photo should be in .jpg or .png format and less than 512KB</small> </div> @* Show preview if image path exists *@ @if (!string.IsNullOrEmpty(Model.Image_FilePath) && !string.IsNullOrEmpty(Model.Image_FileName)) { <div> <img src="@Url.Content("~/" + Model.Image_FilePath + Model.Image_FileName)" alt="Agent Photo" style="max-width:120px; max-height:120px;" /> </div> } </div> <div class="border p-3 mb-3"> <h5>Permanent Residence Address</h5> <div class="form-row"> <div class="form-group col-md-4"> @Html.LabelFor(m => m.P_AddressLine1) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.P_AddressLine1, new { @class = "form-control", placeholder = "Address Line 1" }) @Html.ValidationMessageFor(m => m.P_AddressLine1, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.P_AddressLine2) @Html.TextBoxFor(m => m.P_AddressLine2, new { @class = "form-control", placeholder = "Address Line 2" }) </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.P_AddressStateCode) <span class="text-danger">*</span> @Html.DropDownListFor(m => m.P_AddressStateCode, new SelectList(Model.stateMaster, "State_Code", "State_Name"), "Select State", new { @class = "form-control", id = "ddlPState" }) @Html.ValidationMessageFor(m => m.P_AddressStateCode, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.P_AddressDistrictCode) <span class="text-danger">*</span> @Html.DropDownListFor(m => m.P_AddressDistrictCode, new SelectList(Model.districtMaster, "District_Code", "District_Name"), "Select District", new { @class = "form-control", id = "ddlPDistrict" }) @Html.ValidationMessageFor(m => m.P_AddressDistrictCode, "", new { @class = "text-danger" }) </div> </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.P_AddressPIN) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.P_AddressPIN, new { @class = "form-control", placeholder = "PIN Code" }) @Html.ValidationMessageFor(m => m.P_AddressPIN, "", new { @class = "text-danger" }) </div> </div> <div class="border p-3 mb-3"> <h5>Address for Place of Business</h5> <div class="form-row"> <div class="form-group col-md-4"> @Html.LabelFor(m => m.BusinessPlace_AddressLine1) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.BusinessPlace_AddressLine1, new { @class = "form-control", placeholder = "Address Line 1" }) @Html.ValidationMessageFor(m => m.BusinessPlace_AddressLine1, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.BusinessPlace_AddressLine2) @Html.TextBoxFor(m => m.BusinessPlace_AddressLine2, new { @class = "form-control", placeholder = "Address Line 2" }) </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.BusinessPlace_AddressStateCode) <span class="text-danger">*</span> @Html.DropDownListFor(m => m.BusinessPlace_AddressStateCode, new SelectList(Model.stateMaster, "State_Code", "State_Name"), "Select State", new { @class = "form-control", id = "ddlBState" }) @Html.ValidationMessageFor(m => m.BusinessPlace_AddressStateCode, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.BusinessPlace_AddressDistrictCode) <span class="text-danger">*</span> @Html.DropDownListFor(m => m.BusinessPlace_AddressDistrictCode, new SelectList(Model.districtMaster, "District_Code", "District_Name"), "Select District", new { @class = "form-control", id = "ddlBDistrict" }) @Html.ValidationMessageFor(m => m.BusinessPlace_AddressDistrictCode, "", new { @class = "text-danger" }) </div> </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.BusinessPlace_AddressPIN) <span class="text-danger">*</span> @Html.TextBoxFor(m => m.BusinessPlace_AddressPIN, new { @class = "form-control", placeholder = "PIN Code" }) @Html.ValidationMessageFor(m => m.BusinessPlace_AddressPIN, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.SubDivision_Code, "Select Sub Division") <span class="text-danger">*</span> @Html.DropDownListFor(m => m.SubDivision_Code, new SelectList(Model.SubdivMaster, "SubDiv_Code", "SubDiv_Name"), "Select Sub Division", new { @class = "form-control", id = "ddlSubDiv" }) @Html.ValidationMessageFor(m => m.SubDivision_Code, "", new { @class = "text-danger" }) </div> </div> <div class="border p-3 mb-3"> <h5>Address for Official Communication</h5> <div class="form-group form-check"> @Html.CheckBoxFor(m => m.IsSameBussinessAdd_CommAdd, new { @class = "form-check-input", id = "chkSameAsBusiness" }) <label class="form-check-label" for="chkSameAsBusiness">Is Your Communication Address same as Business Address?</label> </div> <div id="commAddressFields"> <div class="form-row"> <div class="form-group col-md-4"> @Html.LabelFor(m => m.BComm_AddressLine1) @Html.TextBoxFor(m => m.BComm_AddressLine1, new { @class = "form-control", placeholder = "Address Line 1" }) @Html.ValidationMessageFor(m => m.BComm_AddressLine1, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-4"> @Html.LabelFor(m => m.BComm_AddressLine2) @Html.TextBoxFor(m => m.BComm_AddressLine2, new { @class = "form-control", placeholder = "Address Line 2" }) </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.BComm_AddressStateCode) @Html.DropDownListFor(m => m.BComm_AddressStateCode, new SelectList(Model.stateMaster, "State_Code", "State_Name"), "Select State", new { @class = "form-control", id = "ddlCommState" }) @Html.ValidationMessageFor(m => m.BComm_AddressStateCode, "", new { @class = "text-danger" }) </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.BComm_AddressDistrictCode) @Html.DropDownListFor(m => m.BComm_AddressDistrictCode, new SelectList(Model.districtMaster, "District_Code", "District_Name"), "Select District", new { @class = "form-control", id = "ddlCommDistrict" }) @Html.ValidationMessageFor(m => m.BComm_AddressDistrictCode, "", new { @class = "text-danger" }) </div> </div> <div class="form-group col-md-2"> @Html.LabelFor(m => m.BComm_AddressPIN) @Html.TextBoxFor(m => m.BComm_AddressPIN, new { @class = "form-control", placeholder = "PIN Code" }) @Html.ValidationMessageFor(m => m.BComm_AddressPIN, "", new { @class = "text-danger" }) </div> </div> </div> <button type="submit" class="btn btn-primary">Update</button> <button type="reset" class="btn btn-secondary ml-2">Reset</button>}
@section Scripts {
<script> // Toggle communication address fields based on checkbox $(document).ready(function () { function toggleCommAddress() { if ($('#chkSameAsBusiness').is(':checked')) { $('#commAddressFields').hide(); } else { $('#commAddressFields').show(); } } toggleCommAddress(); $('#chkSameAsBusiness').change(toggleCommAddress); // State-District cascading dropdown for Permanent Residence $('#ddlPState').change(function () { var stateCode = $(this).val(); $.ajax({ url: '@Url.Action("GetDistrictsByState", "Agent")', data: { stateCode: stateCode }, success: function (data) { var $district = $('#ddlPDistrict'); $district.empty().append('<option value="">Select District</option>'); $.each(data, function (i, item) { $district.append('<option value="' + item.District_Code + '">' + item.District_Name + '</option>'); }); } }); }); // Business Address State-District cascading $('#ddlBState').change(function () { var stateCode = $(this).val(); $.ajax({ url: '@Url.Action("GetDistrictsByState", "Agent")', data: { stateCode: stateCode }, success: function (data) { var $district = $('#ddlBDistrict'); $district.empty().append('<option value="">Select District</option>'); $.each(data, function (i, item) { $district.append('<option value="' + item.District_Code + '">' + item.District_Name + '</option>'); }); } }); }); // Communication Address State-District cascading $('#ddlCommState').change(function () { var stateCode = $(this).val(); $.ajax({ url: '@Url.Action("GetDistrictsByState", "Agent")', data: { stateCode: stateCode }, success: function (data) { var $district = $('#ddlCommDistrict'); $district.empty().append('<option value="">Select District</option>'); $.each(data, function (i, item) { $district.append('<option value="' + item.District_Code + '">' + item.District_Name + '</option>'); }); } }); }); }); </script>}
if i click on check button for is address same as permant address, will it populate all data in textboxes?
- Assistant
No, based on the provided code, clicking the "Is Your Communication Address same as Business Address?" checkbox will not automatically populate the communication address fields with the business address data.
Here's what the current JavaScript code for that checkbox does:
- It checks if the checkbox with
id="chkSameAsBusiness"is checked. - If it is checked (
is(':checked')), it hides the entiredivblock withid="commAddressFields". - If it is not checked, it shows the
divblock withid="commAddressFields".
The code only controls the visibility of the communication address fields. It does not include any logic to read the values from the business address fields and copy them into the communication address fields when the checkbox is checked.
To achieve the behavior where the fields are populated, you would need to add JavaScript code within the
changeevent handler (or thetoggleCommAddressfunction) to explicitly copy the values when the checkbox is checked.Here's an example of the JavaScript code you would need to add inside your
toggleCommAddressfunction to achieve this:<script> $(document).ready(function () { function toggleCommAddress() { if ($('#chkSameAsBusiness').is(':checked')) { // If checked, hide the fields and copy values $('#commAddressFields').hide(); // Copy values from Business Address to Communication Address $('#@Html.IdFor(m => m.BComm_AddressLine1)').val($('#@Html.IdFor(m => m.BusinessPlace_AddressLine1)').val()); $('#@Html.IdFor(m => m.BComm_AddressLine2)').val($('#@Html.IdFor(m => m.BusinessPlace_AddressLine2)').val()); $('#ddlCommState').val($('#ddlBState').val()); // Copy State value // Trigger change event on Communication State dropdown to load districts for it $('#ddlCommState').trigger('change'); // Important for cascading dropdown // Set the District value *after* the districts are loaded (might need a slight delay or promise handling for async) // For simplicity here, assuming the state change is fast or districts already exist. // A more robust approach might wait for the GetDistrictsByState AJAX call to complete. var selectedBDistrict = $('#ddlBDistrict').val(); // You might need a slight delay or check if options are loaded here // For basic cases, setting it immediately might work if the target options exist $('#ddlCommDistrict').val(selectedBDistrict); $('#@Html.IdFor(m => m.BComm_AddressPIN)').val($('#@Html.IdFor(m => m.BusinessPlace_AddressPIN)').val()); } else { // If not checked, show the fields and optionally clear them $('#commAddressFields').show(); // Optionally clear the communication fields when unchecking $('#@Html.IdFor(m => m.BComm_AddressLine1)').val(''); $('#@Html.IdFor(m => m.BComm_AddressLine2)').val(''); $('#ddlCommState').val(''); $('#ddlCommDistrict').empty().append('<option value="">Select District</option>'); // Clear and reset District dropdown $('#@Html.IdFor(m => m.BComm_AddressPIN)').val(''); } } // --- Rest of your existing script --- toggleCommAddress(); // Call on page load $('#chkSameAsBusiness').change(toggleCommAddress); // Call on change // State-District cascading dropdown for Permanent Residence $('#ddlPState').change(function () { var stateCode = $(this).val(); $.ajax({ url: '@Url.Action("GetDistrictsByState", "Agent")', data: { stateCode: stateCode }, success: function (data) { var $district = $('#ddlPDistrict'); $district.empty().append('<option value="">Select District</option>'); $.each(data, function (i, item) { $district.append('<option value="' + item.District_Code + '">' + item.District_Name + '</option>'); }); // If you have an initial value for P_AddressDistrictCode in the model, // you might need to set it here after loading districts. if ('@Model.P_AddressDistrictCode' && '@Model.P_AddressStateCode' === stateCode) { $district.val('@Model.P_AddressDistrictCode'); } } }); }).trigger('change'); // Trigger change on load to populate initial district if state is set // Business Address State-District cascading $('#ddlBState').change(function () { var stateCode = $(this).val(); $.ajax({ url: '@Url.Action("GetDistrictsByState", "Agent")', data: { stateCode: stateCode }, success: function (data) { var $district = $('#ddlBDistrict'); $district.empty().append('<option value="">Select District</option>'); $.each(data, function (i, item) { $district.append('<option value="' + item.District_Code + '">' + item.District_Name + '</option>'); }); // If you have an initial value for BusinessPlace_AddressDistrictCode in the model, // you might need to set it here after loading districts. if ('@Model.BusinessPlace_AddressDistrictCode' && '@Model.BusinessPlace_AddressStateCode' === stateCode) { $district.val('@Model.BusinessPlace_AddressDistrictCode'); } } }); }).trigger('change'); // Trigger change on load // Communication Address State-District cascading $('#ddlCommState').change(function () { var stateCode = $(this).val(); $.ajax({ url: '@Url.Action("GetDistrictsByState", "Agent")', data: { stateCode: stateCode }, success: function (data) { var $district = $('#ddlCommDistrict'); $district.empty().append('<option value="">Select District</option>'); $.each(data, function (i, item) { $district.append('<option value="' + item.District_Code + '">' + item.District_Name + '</option>'); }); // This block is important if you have an initial value for BComm_AddressDistrictCode in the model // or if you are copying from the business address. if (stateCode && $('#chkSameAsBusiness').is(':checked')) { // If same as business and state was just set (possibly by copying) // Check if the business district value exists in the loaded data var selectedBDistrict = $('#ddlBDistrict').val(); if (data.some(item => item.District_Code == selectedBDistrict)) { $district.val(selectedBDistrict); } } else if ('@Model.BComm_AddressDistrictCode' && '@Model.BComm_AddressStateCode' === stateCode) { // If not same as business OR initial load and model has comm address data $district.val('@Model.BComm_AddressDistrictCode'); } } }); }).trigger('change'); // Trigger change on load // Initial load fixes: Ensure districts are populated if states have values on page load $('#ddlPState').trigger('change'); $('#ddlBState').trigger('change'); // Comm state trigger needs to happen AFTER the business state might have been copied IF the box is checked on load // A slight delay or putting it in a separate block might be better if box is checked on load // Or, ensure the toggleCommAddress function triggers the comm state change when it copies // The added trigger('change') within toggleCommAddress handles the copy case. // For initial load where the box is NOT checked but model has comm address data, the trigger after the definition handles it. }); </script>Explanation of the added code:
- We use
@Html.IdFor(m => m.PropertyName)to get the dynamically generated ID of the HTML elements rendered by theHtmlHelper. This is safer than hardcoding IDs. $('#ID_of_Target_Field').val($('#ID_of_Source_Field').val());is the core jQuery line that copies the value from one input field to another.- For the dropdowns (
ddlCommState,ddlCommDistrict), we copy the value (State_Code, District_Code). jQuery's.val()for a select element sets the selected option based on the value. - Crucially, when copying the state (
$('#ddlCommState').val($('#ddlBState').val());), we need to trigger thechangeevent on the communication state dropdown ($('#ddlCommState').trigger('change');). This is because your existing cascading logic relies on thechangeevent to load the list of districts. If you just set the value without triggeringchange, the district dropdown won't update with the correct options for the newly set state. - Setting the district value (
$('#ddlCommDistrict').val(selectedBDistrict);) after triggering the state change is necessary, but you need to be aware that the district options are loaded asynchronously via AJAX. In a simple scenario, setting it immediately might work if the AJAX call is very fast or the list of districts for the copied state is already loaded. For a robust solution, you might need to set the district value within the success callback of the communication address district AJAX call, ensuring the option exists before trying to select it. The example adds a basic attempt at setting it right after triggering the state change and includes a more robust check within the CommState change handler's success function. - The
elseblock now includes code to clear the communication address fields when the checkbox is unchecked, preventing stale data from being submitted if the user decides to enter a different address.
So, in its current state, clicking the checkbox only hides/shows fields. It doesn't copy data. You would need to add the data-copying logic as shown above.
- It checks if the checkbox with
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.