Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在MVC中将DropDownList添加到剑道网格_Asp.net Mvc_Kendo Ui_Grid_Html.dropdownlistfor_Client Templates - Fatal编程技术网

Asp.net mvc 在MVC中将DropDownList添加到剑道网格

Asp.net mvc 在MVC中将DropDownList添加到剑道网格,asp.net-mvc,kendo-ui,grid,html.dropdownlistfor,client-templates,Asp.net Mvc,Kendo Ui,Grid,Html.dropdownlistfor,Client Templates,我正试图在这个文档的帮助下向剑道网格添加一个dropdownlist : 事实上,我遵循了完全相同的方式,但我不知道剑道网格如何理解它必须在clientTemplate中放置dropdownlist?! 是否必须在某个地方定义clientTemplate?您必须通过将其添加到网格来定义clientTemplate。ClientDetailTemplateId(“模板”) 然后您可以将DropDownList添加到模板中 <script id="template" type="text/k

我正试图在这个文档的帮助下向剑道网格添加一个dropdownlist :

事实上,我遵循了完全相同的方式,但我不知道剑道网格如何理解它必须在clientTemplate中放置dropdownlist?!
是否必须在某个地方定义clientTemplate?

您必须通过将其添加到网格
来定义clientTemplate。ClientDetailTemplateId(“模板”)

然后您可以将DropDownList添加到模板中

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().DropDownList()
       //build the dropdownlist
       .ToClientTemplate()
    )
</script>

@(Html.Kendo().DropDownList())
//建立下拉列表
.ToClient模板()
)

演示:

为了增加答案的组合,这里有一个迟来的答案

  • 在ViewModel中创建列表
  • 将您的Model.PropertyId视为外键
例如

columns.ForeignKey(x=>x.ChangeTypeId,Model.ChangeTypes,“Id”, “变更类型名称”)

示例视图:

@(Html.Kendo().Grid<ChangeRequest>()
              .Columns(columns =>
              {
                  columns.Bound(x => x.Id)
                      .Visible(false);
                  columns.Bound(x => x.Description)
                      .Title("Description")
                      .Width(100);
                  columns.ForeignKey(x => x.ChangeTypeId, Model.ChangeTypes, "Id", "ChangeTypeName")
                      .Title("Data Type")
                      .Width(50);
                  columns.Command(command => { command.Edit(); command.Destroy(); }).Width(100);
              })
              .Name("gridChangeRequest")
              .ToolBar(toolbar => toolbar.Create())
              .Editable(editable => editable.Mode(GridEditMode.InLine))
              .Pageable()
              .Sortable()
              .Scrollable()
              .BindTo(Model.RTUDeviceCustomRegisterModbuses)
              .DataSource(dataSource => dataSource.Ajax()
                                                  .ServerOperation(true)
                                                  .PageSize(50)
                                                  .Model(model => { model.Id(m => m.Id); })
                                                  .Create(update => update.Action("Create", "ChangeRequest", new { Area = "Documents" }))
                                                  .Update(update => update.Action("Update", "ChangeRequest", new { Area = "Documents" }))
                                                  .Destroy(update => update.Action("Destroy", "ChangeRequest", new { Area = "Documents" }))
                                                  )
              .HtmlAttributes(new { @class = "", @style = "height: 400px;" }))
public class ChangeRequestFormViewModel : ViewModelBase
{
    #region <Constructors>

    public ChangeRequestFormViewModel(IApplication application) : base(application)
    {
        InitializeCreateEmpty();
    }

    #endregion

    #region <Properties>

    public ChangeRequestDocument Entity { get; set; }

    #region lookups

    public List<ChangeType> ChangeTypes { get; set; }

    #endregion

    #endregion

    #region <Methods>

    private void InitializeCreateEmpty()
    {
        var builder = Application.ChangeRequestDocumentXmlDataSetBuilder; //<-- This object is specific to my (particular) application
        var dataset = builder.CreateEmpty();

        Entity = dataset.Form;

        ChangeTypes = dataset.ChangeTypes;
    }

    #endregion
}
@(Html.Kendo().Grid())
.列(列=>
{
columns.Bound(x=>x.Id)
.可见(假);
columns.Bound(x=>x.Description)
.标题(“说明”)
.宽度(100);
columns.ForeignKey(x=>x.ChangeTypeId,Model.ChangeTypes,“Id”,“ChangeTypeName”)
.标题(“数据类型”)
.宽度(50);
Command(Command=>{Command.Edit();Command.Destroy();}).Width(100);
})
.Name(“gridChangeRequest”)
.ToolBar(ToolBar=>ToolBar.Create())
.Editable(可编辑=>Editable.Mode(GridEditMode.InLine))
.Pageable()
.Sortable()
.Scrollable()
.BindTo(型号.RTUDeviceCustomRegisterModbus)
.DataSource(DataSource=>DataSource.Ajax()
.ServerOperation(真)
.页面大小(50)
.Model(Model=>{Model.Id(m=>m.Id);})
.Create(update=>update.Action(“创建”、“更改请求”、新建{Area=“Documents”}))
.Update(Update=>Update.Action(“更新”,“变更请求”,新的{Area=“Documents”}))
.Destroy(update=>update.Action(“Destroy”、“ChangeRequest”、new{Area=“Documents”}))
)
.HtmlAttributes(新的{@class=”,@style=“高度:400px;”}))
示例视图模型:

@(Html.Kendo().Grid<ChangeRequest>()
              .Columns(columns =>
              {
                  columns.Bound(x => x.Id)
                      .Visible(false);
                  columns.Bound(x => x.Description)
                      .Title("Description")
                      .Width(100);
                  columns.ForeignKey(x => x.ChangeTypeId, Model.ChangeTypes, "Id", "ChangeTypeName")
                      .Title("Data Type")
                      .Width(50);
                  columns.Command(command => { command.Edit(); command.Destroy(); }).Width(100);
              })
              .Name("gridChangeRequest")
              .ToolBar(toolbar => toolbar.Create())
              .Editable(editable => editable.Mode(GridEditMode.InLine))
              .Pageable()
              .Sortable()
              .Scrollable()
              .BindTo(Model.RTUDeviceCustomRegisterModbuses)
              .DataSource(dataSource => dataSource.Ajax()
                                                  .ServerOperation(true)
                                                  .PageSize(50)
                                                  .Model(model => { model.Id(m => m.Id); })
                                                  .Create(update => update.Action("Create", "ChangeRequest", new { Area = "Documents" }))
                                                  .Update(update => update.Action("Update", "ChangeRequest", new { Area = "Documents" }))
                                                  .Destroy(update => update.Action("Destroy", "ChangeRequest", new { Area = "Documents" }))
                                                  )
              .HtmlAttributes(new { @class = "", @style = "height: 400px;" }))
public class ChangeRequestFormViewModel : ViewModelBase
{
    #region <Constructors>

    public ChangeRequestFormViewModel(IApplication application) : base(application)
    {
        InitializeCreateEmpty();
    }

    #endregion

    #region <Properties>

    public ChangeRequestDocument Entity { get; set; }

    #region lookups

    public List<ChangeType> ChangeTypes { get; set; }

    #endregion

    #endregion

    #region <Methods>

    private void InitializeCreateEmpty()
    {
        var builder = Application.ChangeRequestDocumentXmlDataSetBuilder; //<-- This object is specific to my (particular) application
        var dataset = builder.CreateEmpty();

        Entity = dataset.Form;

        ChangeTypes = dataset.ChangeTypes;
    }

    #endregion
}
公共类ChangeRequestFormViewModel:ViewModelBase
{
#区域
公共ChangeRequestFormViewModel(IAApplication应用程序):基础(应用程序)
{
初始化createempty();
}
#端区
#区域
公共ChangeRequestDocument实体{get;set;}
#区域查找
公共列表更改类型{get;set;}
#端区
#端区
#区域
私有void初始化项createempty()
{

var builder=Application.ChangeRequestDocumentXmlDataSetBuilder;//我想把dropdownlist放在表的一列中,比如说第3列,那么在这种情况下,建议的解决方案如何知道把dropdownlist放在哪里?