when i use this code i get internal server error :
<script>
function LoadRegion() {
var countryId = document.getElementById("country").value;
$.ajax({
type: 'POST',
url: "../Account/Register",
data: $('#form').serialize(),
dataType: 'json'
});
}
</script>
My question is : how can i pass this value in controller in specific field?
Controller:
[HttpPost]
public ActionResult Register(IndexPageModel model)
{
model.Register.Country = new SelectList(manager.GetCountries(), "Id", "Name");
//I need to put here SelectCountryId->model.Register.Region = new SelectList(manager.GetRegions(model.Register.SelectCountryId), "Id", "Name");
return View(model);
}
View:
@Html.DropDownListFor(m => m.Register.SelectCountryId,
Model.Register.Country,
"Select country",
new { id = "country",
@class = "form-control",
@onchange ="LoadRegion();"
}
)