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

[Solved] View not found on ajax editing

1 Answer 128 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.
Chris McNear
Top achievements
Rank 1
Chris McNear asked on 06 Feb 2012, 07:11 AM
Ok so I have what is probably a overly stupid question but oh well here goes....

I am trying to model my grid after the example on the ajax editing demo.  however when I attempt to run the code and commit an edit or delete I get an error that the view '_UpdateUser' or its master can't be found..... Which I of course understand means that it is looking for that view becuase that is the name of the action.  I have also looked at the source code for the examples (included with the download) and When I look at AjaxEditingController.cs in the project the return View statements on the Add/edit/delete all get highlighted red (could not resolve view)

Is there some other "magic" going on in the background on the hosted demo site that makes it work? Not the method gets called and my database does get updated correctly its just having trouble redisplaying the grid....


just in case here is the controller or that method in the controller

[Authorize(Roles = "Users")]
        [GridAction]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult _UpdateUser(int UserID)
        {
            var database = new Models.MWestEntities();
 
            var foundStatus = (from myStatus in database.Users where myStatus.UserID == UserID select new StorySubmitter() { Email = myStatus.Email, FirstName = myStatus.FirstName, LastName = myStatus.LastName, PostalCode = myStatus.PostalCode, UserId = myStatus.UserID }).FirstOrDefault();
 
            if (foundStatus == null)
            {
                //A customer with the specified id does not exist - redisplay the grid
 
                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                return RedirectToAction("DisplayUsers", this.GridRouteValues());
            }
 
            //Perform model binding (fill the customer properties and validate it).
            if (TryUpdateModel(foundStatus))
            {
                var foundUser = (from myStatus in database.Users where myStatus.UserID == UserID select myStatus).FirstOrDefault();
                foundUser.Email = foundStatus.Email;
                foundUser.FirstName = foundStatus.FirstName;
                foundUser.LastName = foundStatus.LastName;
                foundUser.PostalCode = foundStatus.PostalCode;
 
 
                //The model is valid - update the customer and redisplay the grid.
                //should just have to save since its in EF
                database.SaveChanges();
 
                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
 
            }
 
            //The model is invalid - render the current view to show any validation errors
 
            return View();
        }

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 06 Feb 2012, 08:47 AM
Hello Chris,

Basically when your Grid is configured to use Ajax binding the select/insert/update/delete action methods should be decorated with the GridAction attribute and should use the GridModel class as a model.
So in your case the return statement should look like this:
 
return View(new GridModel(database.Users));


Regards,
Petur Subev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Grid
Asked by
Chris McNear
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or