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

[Solved] MVC3 Razor - Ajax Binding Error 404

6 Answers 384 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Les
Top achievements
Rank 1
Les asked on 01 Feb 2011, 07:25 PM
Hi Everyone,

First time posting in this Forum and appreciate any help. I am using the Telerik Grid in MVC3 with the Razor View Engine. I followed one of your examples for Ajax databinding. When I do not include an entry for ScriptRegistrar, the data loads and is pageable in the grid but filtering is not enabled (to be expected). Now to my main problem.. when I add '@Html.Telerik().ScriptRegistrar()' to the _Layout.cshtml code file, the filtering is enabled however when I try to page through the records I receive the following error : The requested URL returned 404 - Not Found.

Code Extract Controller:
public ActionResult Index()
        {
            return View(GetClassifications());
        }
  
[GridAction]
public ActionResult _AjaxIndex()
{
              
  return View(new GridModel
  {
    Data = GetClassifications()
  });
  
}
private IEnumerable<ClassificationViewModel> GetClassifications()
   ContextFactory _factory = new ContextFactory();
   var _entityClassification = _factory.GetDataRepository<tbl_AssetClassification>().ReadAll();
   return from classifiction in _entityClassification
   select new ClassificationViewModel
    {
      ClassificationID = classification.Id,
      Classification = classification.Classification
    };
}

Code Extract Index.cshtml
<fieldset>
        <!-- Telerik Grid Control-->
    <legend>Classifications</legend>
         @(Html.Telerik()
            .Grid(Model)
            .Name("Classifications")
            //.PrefixUrlParameters(false)
            .Pageable(pager => pager.PageTo(1).Position(GridPagerPosition.Bottom))
            .DataKeys(keys => keys.Add(dataKeys => dataKeys.ClassificationID))
            .ToolBar(ToolBarCommand => ToolBarCommand.Insert())
            .NoRecordsTemplate("No Data could be retrieved from the database")
            .Columns(columns =>
            {
                columns.Command(command =>
                {
                    command.Delete();
                    command.Edit();
                }).Width(200).Title("");
                //columns.AutoGenerate(true);
                columns.Bound(bound => bound.ClassificationID).Width(100);
                columns.Bound(bound => bound.Classification).Width(100);
                      
            }).Editable(editable => editable.TemplateName("Classification").Mode(GridEditMode.PopUp))
            .DataBinding(dataBinding => dataBinding.Ajax()
                .Select("_AjaxIndex", "Home")
                .Update("Update", "Home")
                .Insert("Insert", "Home")
                .Delete("Delete", "Home")
            )
            .Groupable()
            .Sortable()
            .Filterable()
            )
</fieldset>

Any suggestions on how to resolve this issue?

Best regards - Les.

6 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 02 Feb 2011, 08:29 AM
Hello Les,

Thank you for the detailed description of the problem.

The grid shouldn't be working at all without a ScriptRegistrar on the page, unless you register its scripts manually.

We should start by tracing the 404 error. Please try inspecting the server response with a Firebug or Fiddler. This should give you a clue at what's happening.

Kind regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Les
Top achievements
Rank 1
answered on 02 Feb 2011, 10:11 PM
Thank you very much for your reply, it was much appreciated. I got fiddler to work with VS2010 and resolved the issue, by changing the 'Select' property of the Grid to resolve to the 'Controller'/'Method'.

Thank you again very much. Great controls and support, keep up the good work.

Les

0
Carlos
Top achievements
Rank 1
answered on 29 Mar 2011, 09:12 PM
Hello, im actually have the same problem, bus im use ASP.NET MVC 2 instead RAZR.
But, im receiving error 404 where use ajaz binding.

this is my aspx :

   <%= Html.Telerik().Grid(Model.Usuarios)
                   .DataBinding(dataBinding => dataBinding.Ajax().Select("Grid", "Usuarios"))
                   .Name("Usuarios")
                   .Columns(columns =>
                    {
                        columns.Bound(o => o.Id).Filterable(false);
                        columns.Bound(o => o.Nome);
                        columns.Bound(o => o.Perfil);
                        columns.Bound(o => o.Status);
                        columns.Bound(o => o.Cadastro);
                                                                                                
                    })
                    .Pageable()

               %>


and, this is my controller :

     public ActionResult Index()
        {
            UsuariosViewData vd = new  UsuariosViewData();
            UsuarioBO usrs = new UsuarioBO();
            vd.Usuarios = usrs.GetUsusarios();
           
            return View(vd);
        }

        [GridAction]
        public ActionResult Grid()
        {
            UsuarioBO usrs = new UsuarioBO();
            return View(new GridModel
            {
                Data = usrs.GetUsusarios()
   
            });
            //return View(new GridModel(usrs.GetUsusarios()));
        }


best regards
Carlos
0
Michel
Top achievements
Rank 1
answered on 21 May 2011, 08:09 PM
@Les: Can you please be more specific on how you corrected the problem? There is no Select 'property' on the Grid. Would you mind posting the code that fixed teh problem for you? I'm having the same issue and I can't find my way out of it.
Thanks
Mike
0
Les
Top achievements
Rank 1
answered on 24 May 2011, 04:44 PM
Hi Mike,

Did you by any chance install Fiddler to help resolve the problem? I find this tool extremely helpful in resolving request issues. I cannot remember what I did at the time, and failed to take note of the issue.. typical :(.

I took a look at my own code.. and it looks identical for the 'Select' operation.

Les
0
Les
Top achievements
Rank 1
answered on 24 May 2011, 04:49 PM
Mike,

I also did the following with Fiddler at the time..

  • Open Fiddler2 and press Ctrl+R and add the following code.
    • //Added to enable logging of VS Web Server traffic for ASP.Net MVC if(oSession.host.substr(0,10)=="localhost.")

{

                         oSession.host=oSession.host.replace("localhost.","127.0.0.1");        

}



When I debug an application (F5, Ctrl+F5), I add a fullstop after the localhost in the webbrowser which ensures that Fidller picks up the traffic for the VS-Web session. Not sure if that is still a requirement with the most recent release of Fiddler.

Les
Tags
Grid
Asked by
Les
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Les
Top achievements
Rank 1
Carlos
Top achievements
Rank 1
Michel
Top achievements
Rank 1
Share this question
or