Is there any to pass some data from HTML property on changed event data to asp.net core razor pages? I want to get an ID from dropdown list from HTML using JS and pass it to Razor Pages (asp.net core 2) and get the result from the custom method ? Code I want to be look like below if possible :)
JS code
$('#Neighborhood_DistrictId').on('change', function () {
@Model.GetDistrictName($('#Neighborhood_DistrictId').val());
});
On the Razor page
public string GetDistrictName(Guid id)
{
return httpSystemApi.GetByIdAsync<District>("Districts", id).Result.Name;
}
GetDistrictName method is connecting to API and returning the value. I don't want to direct connect to API with JS if there is a way to do what I want
@Model.GetDistrictName is a server side method not Usage directly inside script
var url="http://localhost/{controllername}/{methodname}/id=";
In mvc 5 genrate url from server side and set the client side variable
this is only way for call the controller using javascript or jquery not Directly use server side method in javascript.