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

Grid command button is looking for a View with the same name as the action method

12 Answers 139 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.
Ross Barbieri
Top achievements
Rank 1
Ross Barbieri asked on 01 May 2010, 04:39 PM
Using the Grid with Ajax binding, clicking on the Update button causes a server 500 error with the message "The view [command action method name] or its master was not found".

Or more specific to my code, the complete error message is: 

The view 'UpdateResourceType' or its master was not found. The following locations were searched:
 ~/Views/StaffProfile/UpdateResourceType.aspx
 ~/Views/StaffProfile/UpdateResourceType.ascx
 ~/Views/Shared/UpdateResourceType.aspx
 ~/Views/Shared/UpdateResourceType.ascx


The odd thing about this is that "UpdateResourceType" is the name of the action method associated with the Update method bound to the control.  It is *not* the name of the view in which the page resides.  In other words, the command button is looking for a View with the same name as the action method.

The view file is named ~\Views\EditResourceTypes.aspx, the Controller file is named ~\Controllers\StaffProfileController.cs, and the controller class is called StaffProfileController, and it contains a method called UpdateResourceType.

Here are bits of the code that i hope are relevant:

In Gobal.ascx.cs:

    public class MvcApplication : System.Web.HttpApplication  
    {  
        public static void RegisterRoutes(RouteCollection routes)  
        {  
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
 
            routes.MapRoute(  
                "Default",                                              // Route name  
                "{controller}/{action}/{id}",                           // URL with parameters  
                new { controller = "Home", action = "Index", id = "" }  // Parameter defaults  
            );  
        }  
    } 

In ~\Controllers\StaffProfileController.cs:

    [HandleError]  
    public class StaffProfileController : SWDControllerBase  
    {          
        [HttpPost]  
        [GridAction]  
        public ActionResult UpdateResourceType()   
        {  
        .  
        .  
        .  
        }  
    } 

In ~\Views\EditResourceTypes.aspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<SWDirect.ViewModels.StaffProfileEditResourceTypesViewModel>>" %> 
 
<% Html.Telerik().Grid<SWDirect.ViewModels.StaffProfileEditResourceTypesViewModel>()  
        .Name("TypesGrid")  
        .DataKeys(keys => { keys.Add(rt => rt.StaffResourceType_ID); })   
        .DataBinding(dataBinding => dataBinding.Ajax()  
                    .Select("EditResourceTypes_Ajax", "StaffProfile")  
                    .Insert("InsertResourceType", "StaffProfile")  
                    .Update("UpdateResourceType", "StaffProfile")  
                    .Delete("DeleteResourceType", "StaffProfile")  
         )  
        .ToolBar(commands => commands.Insert())  
        .Columns(columns => 
        {  
            columns.Bound(rt => rt.ResourceTypeName).Width(240).Title("License");  
            columns.Bound(rt => rt.StateName).Width(80).Title("Licensed In");  
            columns.Command(commands =>   
                                {   
                                    commands.Edit();   
                                    commands.Delete();   
                                }).Width(180);  
        })  
        .Render();  
%> 
 

Any ideas why the command buttons are looking for a View rather than an action method?

12 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 May 2010, 11:11 AM
Hi Ross Barbieri,

This can occur of the GridAction attribute does not do its work. Make sure you are using GridModel when returning the result from your action method. Your code should look like this:

[HttpPost] 
[GridAction] 
public ActionResult UpdateResourceType()  
    //other code
    return View(new GridModel(someData));   
}


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
Ross Barbieri
Top achievements
Rank 1
answered on 04 May 2010, 01:55 AM

The action method UpdateResourceType() already looks just as you suggested it should.  But it seems irrelevant since that method is never reached.  The error occurs in trying to invoke that method.

Two methods *are* being reached.  Those are the ones that do the selection, on the initial load and then for ajax refreshes.  Here is what they look like:

        public ActionResult EditResourceTypes()  
        {  
            try 
            {  
                return View(StaffProfileEditResourceTypesViewModel.GetForStaff(StaffLogin.Staff_ID));  
            }  
            catch (Exception ex)  
            {  
                ModelState.AddModelError(String.Empty, GetExceptionMessage(ex));  
            }  
            return View();  
        }  
 
        [GridAction]  
        public ActionResult EditResourceTypes_Ajax()  
        {  
            try 
            {  
                return View(new GridModel(StaffProfileEditResourceTypesViewModel.GetForStaff(StaffLogin.Staff_ID)));  
            }  
            catch (Exception ex)  
            {  
                ModelState.AddModelError(String.Empty, GetExceptionMessage(ex));  
            }  
            return View();  
        }  
 
0
Atanas Korchev
Telerik team
answered on 04 May 2010, 07:44 AM
Hello Ross Barbieri,

I think an exception is being thrown hence the code goes in the catch block and then returns View(); which of course fails because there is no view named EditResourceTypes_Ajax etc. I suggest you check with the debugger what is going on when the method is requested.

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
Nhoj
Top achievements
Rank 1
answered on 19 Apr 2011, 05:21 PM
I am experiencing EXACTLY the same error, but have yet to see a satisfactory solution.  I have tried everything that has been suggested:

- Return the GridModel()
- Various iterations of [HttpPost] and [GridAction] attributes
- Changed everything over to using a ViewModel rather than my Entity Framework type
- Various iterations of the name of the Action method
- Ensuring the Grid is bound to my ViewModel
- Setting up the data keys
- etc (including everything from the postings from Telerik support on this thread.

But...am STILL getting the same message - by the way, Fiddler is invaluable in getting this message - you MUST use it to see what is really going on.

Anybody have the solution???  It MUST have been solved by now, but I just cannot see it anywhere.
0
Nhoj
Top achievements
Rank 1
answered on 21 Apr 2011, 03:58 AM
OK...I FINALLY have it (with a LOT of divine intervention).  The view looks very similar to the other postings about this, as well as the original thread.  However, I had to make a minor adjustment to the Controller.  I've got the pertinent controller code copied below.  The first method is the server side Controller action to get the list of type lists and send them to the grid - all fine.  The second one, however, is AJAX'ified refresh action for the grid.  Simply calls the same code to get the list of Type Lists.  All of the postings out there say to use the return View(new GridModel(model)) technique to get the data to the grid.  However, that NEVER worked.  You can see the other iteration of that I used as well. The thing that DID work was the use of return Json(xxx) - see below.

I'm not sure why I haven't seen this solution anywhere else...so that is why I'm posting it.  You can even see in Fiddler that it is returning JSON - good stuff!  Now I need to get on to figuring out client side validation - another sore spot with this control.

/// <summary>
/// Gets the list of TypeLists - yea...say that again
/// </summary>
public ActionResult TypeCodeList()
{
 
    var model = from p in entityRepository.Find<TypeList>(p => p.IsActive==true)
                select new TypeCodeListViewModel
                {
                    TypeListId = p.TypeListId,
                    Name = p.Name,
                    Description = p.Description,
                    IsActive = p.IsActive
                };
 
    // Get all of the type lists and send them to the view
    return View(model);
 
}
 
/// <summary>
/// The ajaxified Select
/// </summary>
/// <returns></returns>
[GridAction]
public ActionResult _TypeCodeList()
{
 
    var model = from p in entityRepository.Find<TypeList>(p => p.IsActive == true)
                select new TypeCodeListViewModel
                {
                    TypeListId = p.TypeListId,
                    Name = p.Name,
                    Description = p.Description,
                    IsActive = p.IsActive
                };
 
 
    //return View("TypeCodeList", model);                               !! Used this for a while
 
    //return View("TypeCodeList",
    //    new GridModel<TypeCodeListViewModel> { Data = model }         !! Tried this iteration
    //    );
 
 
    return Json(new GridModel(model));                                  //!! This FINALLY worked!!
 
}
0
Gary Davis
Top achievements
Rank 2
answered on 01 Dec 2011, 05:44 PM
I seem to be having the same problem as Ross where the grid has ajax binding and a command button and clicking the command button calls the Server action instead of the Ajax action (according to the sniffer).

I'd expect it to call /checkout/shipoptionselected/018?ShipOptionsGrid-mode=select
 but instead it is calling /checkout/Index/018?ShipOptionsGrid-mode=select

Simply changing Ajax() to Server() does get it to call the correct request.

This does not seem to be a controller issue. It does not seem related to Hhoj's posts either (I'm not getting that far, yet).

I am using the latest Telerik MVC extensions - Q3-2011 (2011.3.1115.340).

Gary Davis
<%= Html.Telerik().Grid(cart.CartCheckout.ShipOptions)
        .Name("ShipOptionsGrid")
        .DataKeys(keys => keys.Add(c => c.Code))
        .DataBinding(d =>
            d.Ajax().Select("shipoptionselected", "checkout")                            
        )
        .Columns(columns =>
        {
            columns.Bound(o => o.Description)
                .Title("Description");
            columns.Bound(o => o.Cost)
                .HeaderHtmlAttributes(textAlignCenter)
                .HtmlAttributes(textAlignRight)
                .Format("{0:c}")
                .Width(70).Title("Cost");
            columns.Command(commands => commands
                    .Select()
                    .ButtonType(GridButtonType.Image)
                )
                .Width(80).Title("Select");
        })
%>
0
Atanas Korchev
Telerik team
answered on 05 Dec 2011, 12:27 PM
Hello Gary Davis,

 This is the default behavior of the select command - it always navigates to a controller method. For client-side selection you can try the Selectable() setting of the grid as shown in the client-selection demo.

Regards,
Atanas Korchev
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
Gary Davis
Top achievements
Rank 2
answered on 05 Dec 2011, 06:13 PM
Thanks, I did switch to using the Selectable() option and got rid of the Select button & column.
However, it does seem that ignoring the action in the ().Select("shipoptionselected", "checkout") is not right.

Gary
0
Atanas Korchev
Telerik team
answered on 06 Dec 2011, 08:54 AM
Hi Gary Davis,

 I am not sure how this is expected to work. How should the Select button behave when you click it in ajax bound scenarios?

Regards,
Atanas Korchev
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
Gary Davis
Top achievements
Rank 2
answered on 06 Dec 2011, 03:12 PM
In my case, I am asking the user to select one of several shipping options in a cart checkout scenario. The ajax request will/should send the row ID to the server so the selection can be saved. There is no real update needed to be returned other than the selected row to be highlighted.

So, I have specified (as shown in my earlier post):

.DataBinding(d =>
d.Ajax().Select("shipoptionselected", "checkout")

So I'd expect it to call the shipoptionselected action in the checkout controller, also passing the row id (so the server knows which row was selected). Instead, it is calling the index action, completely ignoring the shipoptionselected action.

Thanks,
Gary
0
Atanas Korchev
Telerik team
answered on 08 Dec 2011, 09:59 AM
Hi Gary Davis,

 The Select() setting is used for databinding the grid. I guess what you need is to implement a custom command. It can hit an action method with ajax passing the ID of the current row.

Regards,
Atanas Korchev
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
Gary Davis
Top achievements
Rank 2
answered on 08 Dec 2011, 03:29 PM
Aha, thanks, Atanas. I am attempting to use the Select() to call the server via Ajax but not needing to return any data so it really is not databinding.

I will look into the custom command.

Gary
Tags
Grid
Asked by
Ross Barbieri
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ross Barbieri
Top achievements
Rank 1
Nhoj
Top achievements
Rank 1
Gary Davis
Top achievements
Rank 2
Share this question
or