Telerik MVC 网格的编辑器模板不起作用

发布于 2024-12-02 22:39:00 字数 2119 浏览 1 评论 0原文

可能的重复:
Telerik MVC 自定义 AJAX 编辑器模板

我正在将 MVC Telerik 控件与 ASP 一起使用.NET MVC 3 剃刀视图引擎。我正在与网格作斗争。我最初提出了一个问题,但没有找到任何运气。它在这里:

Telerik MVC 自定义 AJAX 编辑器模板

我的视图接受视图模型称为EditGrantApplicationViewModel。该视图上有许多不同类型的控件。文本框、下拉菜单和 Telerik 网格。该系统是教育基金系统,在申请贷款时您必须指定您孩子的详细信息。因此,我认为如果我在网格中显示子项,然后可以通过网格添加子项并将其链接到我的视图模型中的 Children 属性,这对用户来说会更好。

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; }
}

我将网格绑定到视图模型的 Children 属性,如下所示:

@(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))
)

我选择 AJAX 网格的原因是,当我单击网格中的“插入”时,整个页面都会得到验证。我不想将子项添加到此处的数据库中,我只想添加到 Children 属性。

我遇到的问题是编辑器模板。我正在进行内联编辑,我想指定我自己的编辑器模板,因为我想重新排列此模板中的控件。如何为 EditGrantApplicationViewModel.Children 创建编辑器模板?

我创建了一个名为 Children.cshtml 的部分视图,但它没有被拉入我的网格中。有人告诉我让它使用子模型,但是我如何在部分视图中指定它,因为我不能有类似的东西:

@model MyProject.ViewModels.EditGrantApplicationViewModel.Children

我有一个例子,但我无法让它在我的场景中工作。

我这样做的方式正确吗?还有什么可以尝试的?

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 the 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笔绘流年 2024-12-09 22:39:00

我得到了解决方案。

我的视图模型中的 Children 属性是 Children 对象的列表。我在 /Shared/Editor/Templates 中创建了一个名为 Children.cshtml 的部分视图。

我认为 Children.cshtml 应该接收这样的模型:

@model MyProject.ViewModels.EditGrantApplicationViewModel.Children

这是我在 @(Html.Telerik().Grid(Model.Children) 中指定的属性,但它应该接收以下模型对象:该列表由以下内容组成,将 Children 对象命名为:

@model MyProject.DomainObjects.Children

现在它正在被拉出:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文