The guys from Hallo,
I am using ASP.NET MVC with jquery and now it is great. There is simply one question that bothers me. How to handle urls in jquery methods? I really would not want to hard code it, as here:
$(function() {
$.getJSON("/Home/List", function(data) {
var items = "---------------------";
$.each(data, function(i, country) {
items += "" + country.Text + "";
});
$("#Countries").html(items);
});
$("#Countries").change(function() {
$.getJSON("/Home/States/List/" + $("#Countries > option:selected").attr("value"), function(data) {
var items = "---------------------";
$.each(data, function(i, state) {
items += "" + state.Text + "";
});
$("#States").html(items);
});
});
});
It is highly recommended that you use HTML helper methods to create links in MVC, such as Html.ActionLink, Html.BeginForm, so if someone changes the HomeController to display on MyHome instead of Home, there will be no problem.
So, how not to hardcode the URL, as in the example?
Also, I don't want to use ASP.NET Ajax because I agree with this answer asp-net-ajax-vs-jquery-in-asp-net-mvc .
thanks