This question is locked. New answers and comments are not allowed.
Hi,
I use Grid control and is having some issue for inline deleing due to the DataKey. Basically when I click "Delete" link, the request does not include datakey (primarykey for entity) I defined in the grid. This causes the problem when invoke the action. My grid and controller action are defined as follows:
One interest thing is the inline "Delete" shows as link instead of "Button" like the Telerik demo sample. Is there any thing I did it worng in the definition of Grid? Please also see the attach file for screen image. Thanks in advanced.
I use Grid control and is having some issue for inline deleing due to the DataKey. Basically when I click "Delete" link, the request does not include datakey (primarykey for entity) I defined in the grid. This causes the problem when invoke the action. My grid and controller action are defined as follows:
<% Html.Telerik().Grid<ehrEHRGUI.Areas.Patient.ViewModels.AllergyForGridViewModel>() .Name("AllergyGrid") .DataKeys(keys => { keys.Add(a => a.AllergyNo); }) .DataBinding(dataBinding => dataBinding.Ajax() .Select("AjaxAllergyGrid", "PatientHome") .Delete("AjaxAllergyGridDelete", "PatientHome") ) .Columns(columns => { columns.Bound(allergy => allergy.AllergyCode); columns.Bound(allergy => allergy.AllergyTextDescription).Title("Allergy Agent"); columns.Bound(allergy => allergy.AllergyReactionDescription).Title("Reaction"); columns.Bound(allergy => allergy.OnSetDateTime).Format("{0:MM/dd/yyyy}").Title("OnSet Date"); columns.Bound(allergy => allergy.StatusDescription).Title("Status"); columns.Command(commands => { commands.Delete(); }).HtmlAttributes(new { style = "padding:1px;" }).Width(100).Title("Delete"); }) .Pageable(paging => paging.PageSize(5).Style(GridPagerStyles.Numeric)) .Editable(a=>a.Enabled(true).Mode(GridEditMode.InLine)) .Render(); %>
//this is the intial action
public ActionResult PatientAllergies(int userNo, int patientNo)
{
var patientAllergyVM = LoadPatientData.LoadAllergyViewModel(userNo, patientNo, _providerService, _patientService);
return View(patientAllergyVM);
//return View();
}
//this is the action called by Ajax.select
[GridAction]
public ActionResult AjaxAllergyGrid(int userNo, int patientNo)
{
var allergyForGrid = LoadPatientData.LoadAllergyForGridViewModel(userNo, patientNo, _providerService, _patientService);
return View(new GridModel<ehrEHRGUI.Areas.Patient.ViewModels.AllergyForGridViewModel>
{
Data = allergyForGrid
});
}
//this is delete action and it does not get call at all due to allergyNo is null
[HttpPost]
[GridAction]
public ActionResult AjaxAllergyGridDelete(int userNo, int patientNo, int allergyNo)
{
var patientAllergy = _patientService.GetPatientAllergyByAllergyNo(allergyNo);
_patientService.Delete(patientAllergy);
try
{
// Try to save changes, which may cause a conflict.
_patientService.Save(); //save to db, remember to use the same dbcontext with get
}
catch (System.Data.OptimisticConcurrencyException) //in system.data.entity
{
// Resolve the concurrency conflict by refreshing the
// object context before re-saving changes.
_patientService.Refresh("client", patientAllergy);
// Save changes.
_patientService.Save();
}
var allergyForGrid = LoadPatientData.LoadAllergyForGridViewModel(userNo, patientNo, _providerService, _patientService);
return View(new GridModel<ehrEHRGUI.Areas.Patient.ViewModels.AllergyForGridViewModel>
{
Data = allergyForGrid
});
}
One interest thing is the inline "Delete" shows as link instead of "Button" like the Telerik demo sample. Is there any thing I did it worng in the definition of Grid? Please also see the attach file for screen image. Thanks in advanced.