Editor template for Telerik MVC grid not working [duplicate]
Possible Duplicate:
Telerik MVC custom AJAX editor template
I am using the MVC Telerik controls with the ASP.NET MVC 3 razor view engine. I am struggling with the grid. I initially posted a question but did not find any luck with it. It is here:
Telerik MVC custom AJAX editor template
My view accepts a view model called EditGrantApplicationViewModel
. This view has many different types of controls on it. Textboxes, dropdowns and a Telerik grid. The system is an education fund system, and while applying for the loan you have to specify your children's details. So I thought it would be better for the user if I display the children in a grid and then a child can be added via the grid and linked to the Children propery in my view model.
public class EditGrantApplicationViewModel
{
public int Id { get; set; }
public string EmployeeNumber { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IEnumerable<Children> Children { get; set; }
}
I bound the grid to the Children property of t开发者_C百科he view model like such:
@(Html.Telerik().Grid(Model.Children)
.Name("grdChildren")
.Columns(column =>
{
column.Bound(x => x.Id);
column.Bound(x => x.FullName);
})
.DataKeys(keys =>
{
keys.Add(x => x.Id);
})
.DataBinding(dataBinding =>
{
dataBinding.Ajax()
.Select("_SelectAjaxEditing", "Grid")
.Insert("_InsertAjaxEditing", "Grid")
.Update("_SaveAjaxEditing", "Grid")
.Delete("_DeleteAjaxEditing", "Grid");
})
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Text))
.Editable(editing => editing.Mode(GridEditMode.InForm))
)
There reason why I chose an AJAX grid is because when I click insert in the grid then the whole page gets validated. I don't want to add the children to the database here, I just want to add to the Children property.
The issue that I am having is with the editor template. I'm doing inline editing and I want to specify my own editor template because I want to rearrange my controls in this template. How would I create an editor template for EditGrantApplicationViewModel.Children
?
I create a partial view called Children.cshtml
but it is not being pulled into my grid. I was told to have it use use the Children model, but how would I specify this in the partial view as I can't have something like:
@model MyProject.ViewModels.EditGrantApplicationViewModel.Children
I got an example but I can't get it to work in my scenario.
Am I doing this the right way? What else can be tried?
I got the solution.
The Children property in my view model is a list of Children objects. I created a partial view in /Shared/Editor/Templates
called Children.cshtml
.
I thought that Children.cshtml should receive the model as such:
@model MyProject.ViewModels.EditGrantApplicationViewModel.Children
which is the property that I specified in @(Html.Telerik().Grid(Model.Children)
but it should receive the model object that the list is made up of, name the Children object:
@model MyProject.DomainObjects.Children
And now it is being pulled through :)
精彩评论