This is a migrated thread and some comments may be shown as answers.

[Solved] Combobox - Load on demand - Ajax - Error 404

2 Answers 44 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Francis Maestri
Top achievements
Rank 1
Francis Maestri asked on 10 Dec 2011, 10:59 AM
Hi, I have been using Telerik for more than a year and it is the first time that I am stuck in a problem that I can't solve. After one day of tests, I have to call for help :)

I am trying to use the combobox from telerik (MVC3 - Razor), example here : http://demos.telerik.com/aspnet-mvc/razor/combobox/ajaxloading

But I can't make it work. Instead of calling the correct URL in the Ajax call, it calls localhost:portnumber/Home/null with the correct data post (text : somestring) so I have a dialog message : Error! The requested URL returned 404 - Not Found

I am using version 2011.3.1115
With previous version (2011.2.914), I have the same error.

I am surely doing something wrong but I can't see what...

Here is my code

View (Test.cshtml)
@{
    ViewBag.Title = "Test";
    Layout = string.Empty;
}
 
<h2>Test</h2>
Search :             @(Html.Telerik().ComboBox()
                .Name("AjaxComboBox")
                .AutoFill(true)
                .DataBinding(binding => binding.Ajax().Select("_Search", "Home"))
                .Filterable(filtering =>
                    {
                        filtering.MinimumChars(3);
                    })
                .HighlightFirstMatch(true)
                )
 
 
@(Html.Telerik().ScriptRegistrar().jQuery(true).Globalization(true).DefaultGroup(group => group.Combined(true).Compress(true)))

My controller (HomeController)
    public class HomeController : Code.MyBaseController
    {
         
        public ActionResult Test()
        {
            return View();
        }
 
        [HttpPost]
        public ActionResult _Search(string text)
        {
            if (text.Length < 3)
            {
                return new JsonResult { Data = null };
            }
            Search s = new Search();
            var result = s.SearchText(text, 10);
            return new JsonResult { Data = result };
        }
    }
 
Base controller :
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
 
namespace SiteSC2.Code
{
    public abstract class MyBaseController : Controller
    {
        private string title;
        protected string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
                ViewBag.Title = value;
            }
        }
 
 
        protected string RenderPartialViewToString()
        {
            return RenderPartialViewToString(null, null);
        }
 
        protected string RenderPartialViewToString(string viewName)
        {
            return RenderPartialViewToString(viewName, null);
        }
 
        protected string RenderPartialViewToString(object model)
        {
            return RenderPartialViewToString(null, model);
        }
 
        protected string RenderPartialViewToString(string viewName, object model)
        {
            if (string.IsNullOrEmpty(viewName) == true)
            {
                viewName = ControllerContext.RouteData.GetRequiredString("action");
            }
 
            ViewData.Model = model;
 
            using (StringWriter sw = new StringWriter())
            {
                ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                viewResult.View.Render(viewContext, sw);
 
                return sw.GetStringBuilder().ToString();
            }
        }
 
        public MyBaseController()
        {
        }
 
    }
}

Global.asax
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
 
routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}/{language}", // URL with parameters
    new { controller = "Home", action = "Index", language=UrlParameter.Optional, id = UrlParameter.Optional } // Parameter defaults
);

Thanks in advance for your help.

Francis.

2 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 12 Dec 2011, 02:01 PM
Hi Francis,

Your code looks OK and at this point I cannot tell what the reason for the problem might be. Could you please provide a sample project so I can examine your exact scenario and current logic more closely? I will check it and get back to you right away.



Greetings,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Francis Maestri
Top achievements
Rank 1
answered on 12 Dec 2011, 10:37 PM
Hi Georgi,

After making a sample project which was working fine, I finally found the bug. It was a routing problem.

so with .DataBinding(binding => binding.Ajax().Select("_Search", "Home", new {id = "something", language = "sv"} )) for the view
and public ActionResult _Search(string text, string id, string language) for the controller

everything is working fine.

sorry for the annoyance.

Francis.
Tags
ComboBox
Asked by
Francis Maestri
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Francis Maestri
Top achievements
Rank 1
Share this question
or