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

Custom Grid Popup with Index id parameter

1 Answer 67 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.
20Below
Top achievements
Rank 1
20Below asked on 11 Oct 2011, 05:15 PM
Hi,
I'm having trouble getting a custom form to properly show up. In my index method I have an optional int.
public ViewResult Index(int? id)
        {      
            IList<ProjectViewModel> projects = new List<ProjectViewModel>();
            if (id != null)
            {
               //Only get projects for the project group id
            } else {
                //We're at the Index with no id parameter, get all the Projects
            }
                 TheViewModel vm = new TheViewModel(){ Projects = projects };
            //return the view model (contains a Projects property)
                return vm;
        }

So the only time I can get the Popup custom form to work is to have a parameterless Index method:
public ViewResult Index()
{
   //Get me all the projects
}

This won't work for us because we have a navigation bar on the left by which users navigate ProjectGroups and perform on the operations for the Projects for the ProjectGroup's. When the Edit button is clicked, the Grid control seems to pass the parameter of the selected Project (the datakey) into the URL along with some other stuff and this is where things break. A window tries to pop-up, but it actually doesn't contain anything so all you see is the "X" in the upper right of the modal to close it. I appreciate any advice anyone can offer. btw, here is how I'm creating my Grid:
@(Html.Telerik().Grid<TantaComm.DartVue.Services.ViewModels.ProjectViewModel>(Model.Projects)
               .Name("Projects")
               .DataKeys(keys => keys.Add(c => c.ProjectID))
               .DataBinding(databind => databind.Server().Update("Edit", "ProjectGroups"))
               .Columns(columns =>
                   {
                       columns.Bound(c => c.Name);
                       columns.Bound(c => c.Code);
                       columns.Bound(c => c.StartDate).Format("{0:d}");
                       columns.Bound(c => c.IsActive);
                       columns.Add(c => c.ProjectGroups.Count).Title("Groups");
                       columns.Command(cmd => cmd.Edit().ButtonType(GridButtonType.Text));
                   }).Editable(editing => editing.Mode(GridEditMode.PopUp))
                       .Pageable()
                       .Sortable())

1 Answer, 1 is accepted

Sort by
0
20Below
Top achievements
Rank 1
answered on 11 Oct 2011, 07:15 PM
Here is a working solution so far. I changed the parameter "id" to "projectGroupId" and this seems to work.
public ViewResult Index(int? projectGroupId)
{
    //If not null, give me projects for the ProjectGroup. Else, give me all projects.
}

Also, the Edit method I accept the projectGroupId so I can do a proper redirect:
public ActionResult Edit(int? id, int? projectGroupId)
        {
            ProjectViewModel project = new ProjectViewModel() { ProjectID = (int)id };
            if (TryUpdateModel(project))
            {
                //The model is valid - update the project and redisplay the grid.
                 
                return RedirectToAction("Index", new { projectGroupId = projectGroupId });
            }
            //The model is invalid - render the current view to show any validation errors
            return View(project);
        }

I'm still interested to hear any other approaches. Thanks!
Tags
Grid
Asked by
20Below
Top achievements
Rank 1
Answers by
20Below
Top achievements
Rank 1
Share this question
or