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

[Solved] Error with Grid and Ajax

14 Answers 316 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.
MGrassman
Top achievements
Rank 2
MGrassman asked on 23 Jun 2010, 10:14 PM
I'm receiving this error. Anything I'm missing?


Exception information:

Exception type: InvalidOperationException

Exception message: The view '_InsertAjaxEditing' or its master was not found. The following locations were searched:

~/Views/Admin/_InsertAjaxEditing.aspx

~/Views/Admin/_InsertAjaxEditing.ascx

~/Views/Shared/_InsertAjaxEditing.aspx

~/Views/Shared/_InsertAjaxEditing.ascx



<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WhatsNewToDo.Web.ViewData.LocationTypeViewData> " %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">  
    <%= Model.SiteTitle %> - <%= Model.PageTitle %> 
</asp:Content> 
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">  
    <h2><%= Model.PageTitle %></h2>  
     <% Html.EnableClientValidation(); %>   
     <% using (Html.BeginForm()) { %> 
     <%= Html.Telerik().Grid(Model.LocationTypeList)  
        .Name("gridLocationTypes")  
        .DataKeys(dataKeys => dataKeys.Add(lt => lt.LocationTypeId))  
        .ToolBar(commands => commands.Insert())  
        .DataBinding(dataBinding =>   
        {  
          dataBinding.Ajax()  
                         .Select("_SelectAjaxEditing", "Admin")  
                         .Insert("_InsertAjaxEditing", "Admin")  
                         .Update("_SaveAjaxEditing", "Admin")  
                         .Delete("_DeleteAjaxEditing", "Admin");  
        })  
        .Columns(columns => 
        {  
            columns.Bound(lt => lt.LocationTypeName);  
            columns.Bound(lt => lt.ModifiedDate).ReadOnly();  
            columns.Bound(lt => lt.ModifiedBy).ReadOnly();  
            columns.Bound(lt => lt.DeletedDate).ReadOnly();  
            columns.Bound(lt => lt.DeletedBy).ReadOnly();  
            columns.Command(commands =>   
            {  
               commands.Edit();  
               commands.Delete();  
             }).Width(180);  
        })  
%> 
<% } %> 
</asp:Content> 

Controller

namespace WhatsNewToDo.Web.Controllers  
{  
 
     [HandleError]  
     public class AdminController : BaseController  
     {  
          [Dependency]  
          public ILocationTypeService service { getset; }  
            
          protected override void Initialize(RequestContext requestContext)  
          {  
               base.Initialize(requestContext);  
          }  
            
          // **************************************  
          // URL: /Location/Create  
          // **************************************  
          [GridAction]  
          public ActionResult LocationTypes()  
          {  
               LocationTypeViewData viewData = ViewDataFactory.CreateBaseViewData<LocationTypeViewData>("Edit Location Types");  
               viewData.LocationTypeList = service.GetAll();  
               return View(viewData);   
               //return View();  
          }  
 
          [GridAction]  
          public ActionResult _SelectAjaxEditing()   
          {  
               LocationTypeViewData viewData = ViewDataFactory.CreateBaseViewData<LocationTypeViewData>("Edit Location Types");  
               viewData.LocationTypeList = service.GetAll();  
               return View(viewData);  
          }  
 
          [AcceptVerbs(HttpVerbs.Post)]  
          [GridAction]  
          public ActionResult _InsertAjaxEditing()  
          {  
               LocationTypeViewData viewData = ViewDataFactory.CreateBaseViewData<LocationTypeViewData>("Edit Location Types");  
               viewData.LocationTypeList = service.GetAll();  
                 
                    LocationType locationType = new LocationType();  
                    locationType.CreatedBy = userProfile.GetUserName();  
                    locationType.ModifiedBy = userProfile.GetUserName();  
                    if(TryValidateModel(locationType)) {  
                         service.Insert(locationType);  
                    }  
                    //return RedirectToAction("LocationTypes");  
                    return View(viewData);  
                 
          }  
 
          [HttpPost]  
          [GridAction]  
          public ActionResult _SaveAjaxEditing(Guid locationTypeId)  
          {  
               return View(new GridModel(service.GetAll()));  
          }  
 
          [HttpPost]  
          public ActionResult _DeleteAjaxEditing(Guid locationTypeId)  
          {  
               return View(new GridModel(service.GetAll()));  
          }  
     }  

14 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Jun 2010, 06:49 AM
Hello MGrassman,

You should be using the GridModel class when implementing ajax binding:

[GridAction]
public ActionResult _AjaxAction()
{
      return View(new GridModel(repository.GetAll());
}


 Please check the ajax binding help article for details.

All the best,
Atanas Korchev
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
MGrassman
Top achievements
Rank 2
answered on 24 Jun 2010, 06:02 PM
Ok sorry for being dense, kinda new to MVC, so I changed the code to use the GridModel and that goes through but now the TryValidateModel doesn't fill the new LocationType created.  If passes the condition and goes to update but the value I have in LocationTypeName does not come through with the submit.  Any Clues?

Also don't know if this is part of the problem but I get a javascript error only on this page with the grid.

at this line "formElement['__MVC_FormValidation'] = this" is null in MicrosoftMVCValidation.js.



[AcceptVerbs(HttpVerbs.Post)]  
          [GridAction]  
          public ActionResult _InsertAjaxEditing()  
          {  
               //LocationTypeViewData viewData = ViewDataFactory.CreateBaseViewData<LocationTypeViewData>("Edit Location Types");  
               //viewData.LocationTypeList = service.GetAll();  
                 
                    LocationType locationType = new LocationType();  
                    locationType.CreatedBy = userProfile.GetUserName();  
                    locationType.ModifiedBy = userProfile.GetUserName();  
                    if(TryValidateModel(locationType)) {  
                         service.Insert(locationType);  
                    }  
                    //return RedirectToAction("LocationTypes");  
                    return View(new GridModel(service.GetAll()));  
                 
          } 
0
Atanas Korchev
Telerik team
answered on 25 Jun 2010, 06:43 AM
Hello MGrassman,

I am pretty positive that the JavaScript error is related with this problem. However I am not sure how to reproduce it locally. Please open a support ticket and send us a small running application which demonstrates your problem. This would help us troubleshoot it and provide a solution.

Regards,
Atanas Korchev
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
Jim Simmermon
Top achievements
Rank 1
answered on 14 Sep 2010, 07:55 PM
Did you ever get past the null problem on this line of code:

formElement[

'__MVC_FormValidation'] = this

 



I am also having problems getting past this as formElement is always null.

Thanks,

jim
0
Carson
Top achievements
Rank 1
answered on 11 Nov 2010, 04:16 PM
I am having the same error as the original post. When my GridAction returns, it tries to find a regular view, instead of sending the JSON to the previous view. I am correctly using the GridModel wrapper.  I have also already tried updating jquery.validate.js to version 1.7.

What else could it be?!
Thanks.

Exception Details: System.InvalidOperationException: The view '_AjaxBinding' or its master was not found. The following locations were searched:
~/Views/G72Htdb/_AjaxBinding.aspx
~/Views/G72Htdb/_AjaxBinding.ascx
~/Views/Shared/_AjaxBinding.aspx
~/Views/Shared/_AjaxBinding.ascx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Htdb3Mvc"%>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Hazard List
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3>Hazard List</h3>
    <% Html.Telerik().Grid<Hazard>()
        .Name("HazardsGrid")
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_AjaxBinding", "G72Htdb"))
        .Columns(columns =>
        {
            columns.Bound(o => o.HazardId).Title("Id").Width(30).Filterable(false);
            columns.Bound(o => o.Name).Title("Name").Width(100);             
        })
        .Groupable()
        .Sortable()
        .Scrollable()
        .Pageable()
        .Filterable(filtering => filtering.Enabled(true))
        .Resizable(resizing => resizing.Columns(true))
        .Render();
    %>
</asp:Content>

[BCIAuthorize(Roles = SiteRoles.Manager | SiteRoles.Analyst)]
public ActionResult HazardGrid()
{
    return View();
}
 
// Used for the Ajax binding
[GridAction]
public ActionResult _AjaxBinding()
{
    IQueryable<Hazard> hazList = HazardRepository.GetAll();
    return View(new GridModel(hazList));
}
0
Atanas Korchev
Telerik team
answered on 11 Nov 2010, 04:28 PM
Hi Carson,

As far as I know this could happen only if:

  1. The GridAction attribute is missing
  2. You are not using GridModel
  3. The request is not ajax - HttpContext.Request.IsAjaxRequest() returns false.

You can try debugging with the source code of Telerik Extensions for ASP.NET MVC. Check the OnActionExecuted method of the GridActionAttribute class.

Regards,
Atanas Korchev
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
Atanas Korchev
Telerik team
answered on 11 Nov 2010, 04:29 PM
Hi Carson,

As far as I know this could happen only if:

  1. The GridAction attribute is missing
  2. You are not using GridModel
  3. The request is not ajax - HttpContext.Request.IsAjaxRequest() returns false.

You can try debugging with the source code of Telerik Extensions for ASP.NET MVC. Check the OnActionExecuted method of the GridActionAttribute class.


Regards,
Atanas Korchev
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
Carson
Top achievements
Rank 1
answered on 11 Nov 2010, 05:12 PM
Thanks Atanas.
Yes, I did just that. The OnActionExecuted method executes perfectly and filterContext.Result is set to a well-formed JsonResult object.
So, the problem is happening somewhere after that. Of course, that sounds like maybe in the native MVC2 framework. Yuck.

Any other suggestions?

Thanks.

Edit:
I checked IsAjaxRequest() to be certain. It was true.

[GridAction]
public ActionResult _AjaxBinding()
{
    bool ajax = HttpContext.Request.IsAjaxRequest();  //ajax = true!
    IQueryable<Hazard> hazList = HazardRepository.GetAll();
    return View(new GridModel(hazList));
}

0
Atanas Korchev
Telerik team
answered on 11 Nov 2010, 05:16 PM
Hi Carson,

 I can't give other suggestions without a repro case. If you attach a sample project which fails in the same way I can troubleshoot it.

Regards,
Atanas Korchev
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
Carson
Top achievements
Rank 1
answered on 11 Nov 2010, 05:59 PM
Hi again.
I copied my solution and pulled all irrelevant code out. I mocked up an IQueryable of fake database objects, passed it into the Grid, and, of course the problem is now totally gone.

Now I just have to check each one of the gazillion things I pulled out to find the culprit.

Why do we love programming, again? :P
0
Carson
Top achievements
Rank 1
answered on 11 Nov 2010, 07:47 PM
Atanas,
I've narrowed my problem down to data. I'm using Entity Framework 4.0.
When I pass an IQueryable collection of simple entities into the GridModel, I get desired results. However, if the entities in the collection are built from a more complex table, such as one with foreign keys, I get the error.

Have you ever looked into Ajax binding on a Grid of complex data entities with FKs and all?
Are there any other known gotchas with complex entities that I might be unaware of? Maybe something to do with JSON and foreign keys?

Again, as far as I can tell, GridAction.OnActionExecuted() is working fine.

Thanks again.

Edit:
Could this be relevant?
0
Atanas Korchev
Telerik team
answered on 12 Nov 2010, 08:46 AM
Hello Carson,

 That stackoverflow article could be relevant. This blog post and this help entry may be relevant as well.

Kind regards,
Atanas Korchev
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
Carson
Top achievements
Rank 1
answered on 12 Nov 2010, 03:44 PM
Yep! That's the one.
Thanks again for your help.
0
Nebras
Top achievements
Rank 1
answered on 22 Dec 2011, 02:55 PM
i had the same problem as JIM ,
and it is solved when i remove the combined and compress from 
@(Html.Telerik().StyleSheetRegistrar()
                      .DefaultGroup(group => group
                         .Add("telerik.common.css")
                           .Add("telerik.Vista.css")
                           .Add("telerik.rtl.css")
                         .Combined(true)
                         .Compress(true)
   )                                    ) to be
@(Html.Telerik().StyleSheetRegistrar()
                      .DefaultGroup(group => group
                         .Add("telerik.common.css")
                           .Add("telerik.Vista.css")
                           .Add("telerik.rtl.css")
                       
   )                                    )

Tags
Grid
Asked by
MGrassman
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
MGrassman
Top achievements
Rank 2
Jim Simmermon
Top achievements
Rank 1
Carson
Top achievements
Rank 1
Nebras
Top achievements
Rank 1
Share this question
or