JQuery ajax request results in an error not found

I am new to MVC and tried to try something, but I cannot get this to work.

I have this script, which should insert a partial view inside the page based on the selection of the drop-down list.

$(function () {
    $('#ddTipologiaFattura').change(function () {
        var selectedID = $(this).val();
        $.ajax({
           url: '/Admin/Fatturazione/GetPartial/' + selectedID,
           contentType: 'application/html; charset=utf-8',
           type: 'GET',
           dataType: 'html'
           })
           .success(function (result) {
               $('#partialPlaceHolder').html(result);
           })
           .error(function (xhr, status, error) {
               alert(status + '\n' + error)
           });
        });
   });

This is my controller ~ / Areas / Admin / Controllers / FatturazioneController.cs

    [RouteArea("Admin")]
    [Route("Fatturazione/{action}")]
    public class FatturazioneController : Controller
    {
        private MyEntity db = new MyEntity();

        public ActionResult GetPartial(int partialViewId)
        {
            if (partialViewId == 0)
            {
                var fatturaAziendaVM = new FatturaPerAziendaViewModel();
                ViewBag.Intestatario = new SelectList(db.Azienda, "AziendaNome", "AziendaNome");
                return PartialView("~/Areas/Admin/Views/Fatturazione/_ListaAziende.cshtml", fatturaAziendaVM);
            }
            var fatturaVM = new FatturaViewModel();
            return PartialView("~/Areas/Admin/Views/Fatturazione/_Intestatario.cshtml", fatturaVM);
        }

I keep getting script error not found . What am I doing wrong?

+4
source share
1 answer

Your route only considers an action, not an identifier, so it doesn’t work. You must either update the route per action to an account for Id, or add an identifier as a query string parameter.

 $.ajax({
       url: '/Admin/Fatturazione/GetPartial?partialViewId=' + selectedID,
+2
source

All Articles