문제

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")' does 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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top