I was using the following link as an example, but that example is using server binding, I'm not sure if I need to make any further changes:
http://demos.telerik.com/aspnet-mvc/editor/editoringrid
My code:
My editor template:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<%= Html.Telerik().Editor()
.Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
.Value(Model)
.Tools(tools => tools
.Clear()
.Bold().Italic().Underline()
.Separator()
.CreateLink().Unlink()
)
%>
I defined my field to use the editor template:
[UIHint("Editor")]
[Required]
[DisplayName("Notes")]
public string Notes
{
get;
set;
}
My controller methods:
[GridAction]
public ActionResult SelectStudentFollowups(int id)
{
return View(new GridModel(new ClientDataContext().StudentFollowups.Where(s => s.StudentID == id)));
}
[HttpPost]
[GridAction]
public ActionResult InsertStudentFollowup(int id)
{
StudentFollowup followup = new StudentFollowup();
followup.StudentID = id;
followup.Notes = HttpUtility.HtmlDecode(followup.Notes);
//Perform model binding (fill the customer properties and validate it).
if (TryUpdateModel(followup))
{
//The model is valid - insert the customer.
studentRepository.InsertStudentFollowup(followup);
studentRepository.Save();
}
//Rebind the grid
return View(new GridModel(new ClientDataContext().StudentFollowups.Where(s => s.StudentID == id)));
}
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult UpdateStudentFollowup(int id)
{
StudentFollowup followup = studentRepository.GetStudentFollowup(id);
int studentID = followup.StudentID;
followup.Notes = HttpUtility.HtmlDecode(followup.Notes);
UpdateModel(followup);
studentRepository.Save();
return View(new GridModel(new ClientDataContext().StudentFollowups.Where(s => s.StudentID == studentID)));
}
The part of the view that renders the grid:
items.Add().Text("Followup").Content(
Html.Telerik().Grid<Client.Models.StudentFollowup>()
.Name("Followup_<#= StudentID #>")
.ToolBar(commands => commands.Insert())
.DataKeys(keys => keys.Add(f => f.StudentFollowupID))
.Columns(columns =>
{
columns.Bound(d => d.DueDate).Width(60).Format("{0:d}").Title("Due Date").Width(150);
columns.Bound(d => d.Notes).Title("Notes").Width(600).Encoded(false);
columns.Command(command =>
{
command.Edit();
command.Delete();
});
})
//.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Sortable()
.DataBinding(dataBinding => dataBinding.Ajax()
.Insert("InsertStudentFollowup", "Student", new { id = "<#= StudentID #>" })
.Update("UpdateStudentFollowup", "Student", new { id = "<#= StudentID #>" })
.Delete("DeleteStudentFollowup", "Student", new { id = "<#= StudentID #>" })
.Select("SelectStudentFollowups", "Student", new { id = "<#= StudentID #>" }))
.ToHtmlString());