I want to detect the page reload by ajax and if the page have been reloaded only then i want to fill my DistrictId variabl. This reload is happening when a user select value from dropdownlist.
Please note that i am writing this code in View and this is for a dropdownlist named
Districtddl
Also
@if (Request.HttpMethod=="POST") {}
is not working
<select class="ddl" id="Districtddl" name="Districtddl">
<option>----Select District----</option>
@foreach (System.Data.DataRow dr in FarmerRegisterFormAndPrint.Models.StoredProcedures.GetAllDistrict().Rows)
{
<option id="@dr["DistrictId"].ToString()">@dr["DistrictName"].ToString()</option>
}
</select>
Quote:
This reload is happening when a user select value from dropdownlist.
@{var DistrictId = "";}
@if (Request.HttpMethod=="POST") {
var DistrictId = Request.Form["Districtddl"].ToString();
}
Quote:
This variable then will be used to pass as parameter to another dropdownlist.
How i can do this.
<select class="ddl" id="Tehsilddl">
<option id="0">----Select District----</option>
@if (!string.IsNullOrEmpty(DistrictId))
{
foreach (System.Data.DataRow dr in FarmerRegisterFormAndPrint.Models.StoredProcedures.GettehsilAccToDistrict(DistrictId).Rows)
{
<option id="@dr["TehsilId"].ToString()">@dr["TehsilName"].ToString()</option>
}
}
</select>
$("#Districtddl").on('change', function () {
var valueDistrictDDl = $(this).find('option:selected').attr('id');
alert(valueDistrictDDl);
var urlInUse = window.location.href;
$.ajax({
url: urlInUse,
dataType: "html",
success: function (data) {
alert("reloaded")
}
});
And if any of this doesnot make any sense to you then please tell me how to set jquery variable to here
(System.Data.DataRow dr in FarmerRegisterFormAndPrint.Models.StoredProcedures.GettehsilAccToDistrict(DistrictId).Rows)
it is a lot easy to get the selected id in jquery but do not know how to pass that to
DistrictId