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

[Solved] Not able to make ajax call

3 Answers 86 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.
Ganesh
Top achievements
Rank 1
Ganesh asked on 18 Feb 2011, 05:34 PM

am not able to make Ajax calls to update the database via the Grid or insert. I have pretty much followed all instructions


<% Html.Telerik().Grid(Model)
           .Name("Company")
           .DataKeys(keys => keys.Add(c => c.ID))
           .ToolBar(commands =>
           {
               if (User.IsInRole("Admin"))
                   commands.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left:0;", title = "Add New Company" });
           })
           .DataBinding(dataBinding => dataBinding.()
        .Select("Index", "Test")
        .Insert("Insert", "Test", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
        .Update("Save", "Test", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText })
        .Delete("Delete", "Test", new { mode = GridEditMode.InLine, type = GridButtonType.ImageAndText }))
           .Columns(columns =>
               {
  
                   columns.Bound(p => p.CompanyName).Width(190);
                   columns.Bound(p => p.Industry).Width(90).Width(230);
                   columns.Bound(p => p.Subsector).Width(230);
                   columns.Bound(p => p.Firm).Width(90).Width(230);
                   columns.Bound(p => p.Address).Width(130);
                   columns.Bound(p => p.City).Width(130);
                   columns.Bound(p => p.Country).Width(130);
                   columns.Bound(p => p.PostalCode).Width(130);
                   columns.Bound(p => p.Phone).Width(130);
                   columns.Bound(p => p.Fax).Width(130);
                   columns.Command(commands =>
                   {
                       if (User.IsInRole("Admin"))
                           commands.Edit().ButtonType(GridButtonType.ImageAndText);
                       if (User.IsInRole("Admin"))
                           commands.Delete().ButtonType(GridButtonType.ImageAndText);
                       commands.Select().ButtonType(GridButtonType.ImageAndText);
                   }).HtmlAttributes(new { nowrap = "nowrap", style = "white-space:nowrap !important;" }).Width(300);
               }
               )
               .Editable(editing => editing.Mode(GridEditMode.InLine))
           .Sortable()
           .Pageable()
           .Selectable()
           .Scrollable()
           .HtmlAttributes(new { style = "overflow-x:auto;overflow-y:hidden" })
           .Render(); %>
            <%} %>

My Controller Method for update functionality

public ActionResult Save(int id, int Industry, int SVBAIndustrySubsector, int LegalFirm, GridEditMode mode, GridButtonType type)
      {
          commonFunctions();
          CompanyDetails companyDetails = CompanyModel.GetCompany(id);
          TryUpdateModel(companyDetails);
          IndustryType objIndustryType = (from i in CompanyModel.GetAllIndustries() where i.IndustryTypeID == Industry select i).FirstOrDefault();
          SubSectorType objSubSectorType = (from s in CompanyModel.GetAllSubSector() where s.SubSectorTypeID == SVBAIndustrySubsector select s).FirstOrDefault();
          LegalFirmType objLegalFirmType = (from l in CompanyModel.GetAllLegalFirm() where l.FirmID == LegalFirm select l).FirstOrDefault();
          companyDetails.Industry = objIndustryType; companyDetails.SVBAIndustrySubsector = objSubSectorType; companyDetails.LegalFirm = objLegalFirmType;
          bool returnValue = CompanyModel.SaveCompany(companyDetails);
          PopulateSearchResults(companyDetails, false, true, false, 0);
          List<CompanyDetails> objCompanyDetails = GetSearchResult(Session["CompanyName"] as string, 0, 0);
          return View(new GridModel(objCompanyDetails));
      }

When i click on update buttonit hits Action in the controller and value will be updated in DB but in my view am getting following Error message . Please Help

3 Answers, 1 is accepted

Sort by
0
Ganesh
Top achievements
Rank 1
answered on 21 Feb 2011, 06:24 AM
Can any one help me on this issue please!
0
Rosen
Telerik team
answered on 21 Feb 2011, 08:39 AM
Hi Ganesh,

It seems that the errors to which you are referring are model state validation errors. Therefore, you should make sure the model which your are saving is in valid state before it is added to the DB (for example the call to TryUpdateModel should not return false).
If you continue to experience difficulties please send us a small runnable project in which this behavior can be observed. This way we will be able to gather more information about your scenario and provide you with more to-the-point answer.

Regards,
Rosen
the Telerik team
0
Daniel
Top achievements
Rank 1
answered on 04 Apr 2011, 06:53 PM
Shouldn't the following line:
.DataBinding(dataBinding => dataBinding.()

Read:
.DataBinding(dataBinding => dataBinding.Ajax()

???
Daniel
Tags
Grid
Asked by
Ganesh
Top achievements
Rank 1
Answers by
Ganesh
Top achievements
Rank 1
Rosen
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or