I am making an asp.net mvc solution with globalization.
I have implemented globalization using resource files (Resources.fr.resx & Resources.nl.resx) and
routes.MapRoute(
"Default",
"{language}/{controller}/{action}/{id}",
new { language="Nl", controller = "Home", action = "Index", id = UrlParameter.Optional },
new { language ="Nl|Fr" }
);
Now i want to make 2 cascading dropdownlists, with something like this:
$('#ddl_Author').change(function () {
var ddlsource = "#ddl_Author";
var ddltarget = "#ddl_Books";
$.getJSON('@Url.Action("Books")', { authorId: $(ddlsource).val() }, function (data) {
$(ddltarget).empty();
$.each(data, function (index, optionData) {
$(ddltarget).append("<option value='" + optionData.Value + "'>" + optionData.Text + "</option>");
});
});
});
My question is what i have to use as url, '@Url.Action("Books")' do开发者_如何转开发es not seem to work...
And this is my controller:
public ActionResult Books(int authorId)
{
var books = _bookService.GetBooks(authorId);
...
return Json(books.ToList(), JsonRequestBehavior.AllowGet);
}
You need to specify the language as it is not an optional parameter in your route:
@Url.Action("Books", new { language = "Fr" })
@Darin Dimitrov
Should this method be preferred over the one in which localizing of a dropdown is done using an XMLDataSource?
精彩评论