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

[Solved] Grid Edit, paging is not working

2 Answers 188 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.
M Ali
Top achievements
Rank 2
M Ali asked on 18 Jun 2012, 03:08 PM
Hi, 

Grid control I am running on server binding, I don't have idea that how it will work I have problem in editing, paging, and delete some what works I don't know how,
When I click on the edit button it take me to the following URL

http://localhost:61122/Donation/FirstLook/656?Donation-mode=edit 

and show me error that there is no view naming FirstLook, In Fact FirstLook is the Action Method I have written in my donation controller 
It show me different URL while I click on Edit Button Like

http://localhost:61122/Donation/Edit/656?Donation-mode=edit   not FirstLook

I have Following code in Partial view named _donationList
@(Html.Telerik().Grid(Model)
       .Name("Donation")
       .DataKeys(keys => keys.Add(c => c.DonationID))
       .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0" }))
       .DataBinding(dataBinding =>
               {
 
                   dataBinding.Server()
                   .Select("FirstLook", "Donation")//, new { ajax = ViewData["ajax"] });
                   //dataBinding.Ajax().Select("_FirstLook", "Donation").Enabled(true)
                   .Insert("Create", "Donation")
                   .Update("Edit", "Donation", new {type = GridButtonType.Text })
                   .Delete("Delete", "Donation", new {type = GridButtonType.Text });
               })
       .Columns(columns =>
       {
            
           columns.Bound(o => o.ReceivedDate).Format("{0:MM/dd/yyyy}").Width(100);
           columns.Bound(o => o.DepositDate).Format("{0:MM/dd/yyyy}").Width(90);
           columns.Bound(o => o.ContactName).Width(160);
           columns.Bound(o => o.DonationAmount).Width(115);
           columns.Bound(o => o.DonationType).Width(90);
           columns.Bound(o => o.ProjectName).Width(130);
           
           columns.Command(commands =>
           {
               commands.Edit().ButtonType(GridButtonType.Text);
               commands.Delete().ButtonType(GridButtonType.Text);
           }).Width(200).Title("Commands");
            
       })
 
               .Scrollable(scrolling => scrolling.Enabled(true))
               .Sortable(sorting => sorting.Enabled(true))
               .Pageable(paging => paging.Enabled(true))
                .Editable(editing => editing.Mode(GridEditMode.InLine))
               //.Filterable(filtering => filtering.Enabled(true))
               //.Groupable(grouping => grouping.Enabled(true))
               .Footer(true)
       )
and My donation controller have following Code, Some Suggestions please
public ActionResult FirstLook(bool? ajax, bool? scrolling, bool? paging, bool? filtering, bool? sorting,
      bool? grouping, bool? showFooter)
        {
            //ViewData["ajax"] = ajax ?? true;
            ViewData["scrolling"] = scrolling ?? true;
            ViewData["paging"] = paging ?? true;
            // ViewData["filtering"] = filtering ?? true;
            // ViewData["grouping"] = grouping ?? true;
            ViewData["sorting"] = sorting ?? true;
            ViewData["showFooter"] = showFooter ?? true;
            return View();
        }
        [GridAction]
        public ActionResult _FirstLook()
        {
            return View(new GridModel());
        }
 
 
        public ActionResult Index()
        {
            List<Donation> model = _dService.GetDonationCollections(applicationID).ToList();
                return View(model);
          
        }
        public ActionResult Create(int? id)
        {
            Donation model = new Donation();
            GetDonationType();
            GetContactList();
            GetProjectType(null);
            GetCategory();
            model.DonationID = id.GetValueOrDefault(0);
            return View("Create", model);
        }
        [HttpPost]
        [GridAction]
        public ActionResult Delete(int id)
        {
            try
            {
                Donation model = _dService.GetDonation(id, applicationID);
                _dService.DeleteDonation(model, applicationID);
                return RedirectToAction("Index");
            }
            catch (Exception e)
            {
                  
                return RedirectToAction("Index");
                 
            }
            
        }
       [GridAction]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(Donation model)
        {
            try
            {
                _dService.SaveDonation(model, applicationID);
                return RedirectToAction("Index");
            }
            catch
            {
                ModelState.AddRuleViolations(model.GetRuleViolations());
                return View("Create", model);
            }
        }
 
        [HttpPost]
        [GridAction]
        public ActionResult Edit(int id)
        {
            Donation model = _dService.GetDonation(id, applicationID);
            GetDonationType();
            GetContactList();
            GetProjectType(model.ProjectId);
            GetCategory();
            if (model != null)
                return View(model);
            else return View();
        }
 
        //
        // POST: /Prayer/Edit/5
 
        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult Edit(int id, Donation model)
        {
            try
            {
                _dService.SaveDonation(model, applicationID);
                return RedirectToAction("Index");
            }
            catch
            {
                ModelState.AddRuleViolations(model.GetRuleViolations());
                return View(model);
            }
        }
    }
}
 
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Dennis
Top achievements
Rank 1
answered on 11 Jul 2012, 08:18 PM
You should be getting an error because you have a comment in the middle of your select line.

.Select("FirstLook", "Donation")//, new { ajax = ViewData["ajax"] });
should be:
.Select("FirstLook", "Donation"), new { ajax = ViewData["ajax"] });
0
M Ali
Top achievements
Rank 2
answered on 12 Jul 2012, 10:02 AM
Thanks a lot, but you have answered too late, That I have solved it 
Your Answer is Also helpful
Tags
Grid
Asked by
M Ali
Top achievements
Rank 2
Answers by
Dennis
Top achievements
Rank 1
M Ali
Top achievements
Rank 2
Share this question
or