Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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
C# 如何在telerik framework ASP.Net MVC中创建不可编辑列_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Telerik - Fatal编程技术网

C# 如何在telerik framework ASP.Net MVC中创建不可编辑列

C# 如何在telerik framework ASP.Net MVC中创建不可编辑列,c#,asp.net,asp.net-mvc,asp.net-mvc-4,telerik,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Telerik,我使用的是telerik MVC框架网格组件,我想使网格的id列可见但不可编辑。 我还希望在用户创建新行时将字段的数据发送到服务器 为此,我使用以下代码 @(Html.Kendo().Grid<MyApplication.Models.CustomerViewModel>() .Name("grid") .Columns(columns => { columns.Bound(c => c.ID).Title("Cod

我使用的是telerik MVC框架网格组件,我想使网格的id列可见但不可编辑。 我还希望在用户创建新行时将字段的数据发送到服务器

为此,我使用以下代码

@(Html.Kendo().Grid<MyApplication.Models.CustomerViewModel>()
      .Name("grid")
      .Columns(columns =>
      {
          columns.Bound(c => c.ID).Title("Code");
          columns.Bound(c => c.companyName).Title("Company Name");
          columns.Bound(c => c.address).Title("Address");
          columns.Bound(c => c.addressNumber).Title("Street").Width(60);
          columns.Bound(c => c.zipCode).Title("ZIP Code").Width(60);
          columns.Bound(c => c.city).Title("City").Width(80);
          columns.Bound(c => c.province).Title("Province").Width(45);
      })
      .Editable(editable => editable.Mode(GridEditMode.InCell))
      .Sortable(sortable =>
      {
          sortable.SortMode(GridSortMode.MultipleColumn);
      })
      .Scrollable()
      .HtmlAttributes(new { style = "height: 710px; top: -25px" })
      .ToolBar(toolbar =>
      {
          toolbar.Create();
          toolbar.Save();
          toolbar.Excel();
          toolbar.Pdf();
      })
      .DataSource(dataSource => dataSource
          .Ajax()
          .Batch(true)
          .Model(model => model.Id(p => p.ID))
          .Model(model =>{
                // Declare a model field and make it readonly
                model.Field(p => p.ID).Editable(false);
                        })
          .Read(read => read.Action("CustomerListViewModels_Read", "Customer"))
          .Create(create => create.Action("CustomerViewModels_Create", "Customer"))
          .Update(update => update.Action("CustomerViewModels_Update", "Customer"))
          .Destroy(destroy => destroy.Action("CustomerViewModels_Destroy", "CustomerList"))
      )
     .Events(events => events.Edit("onEdit"))
        )
@(Html.Kendo().Grid())
.名称(“网格”)
.列(列=>
{
columns.Bound(c=>c.ID).Title(“代码”);
columns.Bound(c=>c.companyName).Title(“公司名称”);
columns.Bound(c=>c.address).Title(“address”);
列。绑定(c=>c.addressNumber)。标题(“街道”)。宽度(60);
columns.Bound(c=>c.zipCode).Title(“邮政编码”).Width(60);
columns.Bound(c=>c.city).Title(“city”).Width(80);
列。绑定(c=>c.province)。标题(“省”)。宽度(45);
})
.Editable(Editable=>Editable.Mode(GridEditMode.InCell))
.Sortable(可排序=>
{
sortable.SortMode(GridSortMode.MultipleColumn);
})
.Scrollable()
.HtmlAttributes(新的{style=“height:710px;top:-25px”})
.ToolBar(ToolBar=>
{
toolbar.Create();
toolbar.Save();
toolbar.Excel();
toolbar.Pdf();
})
.DataSource(DataSource=>DataSource
.Ajax()
.Batch(真)
.Model(Model=>Model.Id(p=>p.Id))
.Model(Model=>{
//声明模型字段并使其为只读
model.Field(p=>p.ID).可编辑(false);
})
.Read(Read=>Read.Action(“CustomerListViewModels\u Read”,“Customer”))
.Create(Create=>Create.Action(“CustomerServiceWModels\u Create”,“Customer”))
.Update(Update=>Update.Action(“CustomerViewModels\u Update”,“Customer”))
.Destroy(Destroy=>Destroy.Action(“CustomerViewModels\u Destroy”、“CustomerList”))
)
.Events(Events=>Events.Edit(“onEdit”))
)

在配置数据源时设置此选项。在这里,您可以告诉网格哪个字段是id,或者通过调用.Editable(false)将绑定的任何字段设置为只读

@(Html.Kendo().Grid())
.名称(“网格”)
.列(列=>
{
columns.Bound(c=>c.ID).Title(“代码”);
columns.Bound(c=>c.companyName).Title(“公司名称”);
columns.Bound(c=>c.address).Title(“address”);
列。绑定(c=>c.addressNumber)。标题(“街道”)。宽度(60);
columns.Bound(c=>c.zipCode).Title(“邮政编码”).Width(60);
columns.Bound(c=>c.city).Title(“city”).Width(80);
列。绑定(c=>c.province)。标题(“省”)。宽度(45);
})
.Editable(Editable=>Editable.Mode(GridEditMode.InCell))
.Sortable(可排序=>
{
sortable.SortMode(GridSortMode.MultipleColumn);
})
.Scrollable()
.HtmlAttributes(新的{style=“height:710px;top:-25px”})
.ToolBar(ToolBar=>
{
toolbar.Create();
toolbar.Save();
toolbar.Excel();
toolbar.Pdf();
})
.DataSource(DataSource=>DataSource
.Ajax()
.Model(mdl=>
{
mdl.Id(“Id”);//告诉网格哪个字段是Id
mdl.Field(fld=>fld.ID).Editable(false);//使ID字段为只读
})
.Batch(真)
.Read(Read=>Read.Action(“CustomerListViewModels\u Read”,“Customer”))
.Create(Create=>Create.Action(“CustomerViewModels_Create”,“Customer”,new{id=“#:data.id#“}))
.Update(Update=>Update.Action(“CustomerViewModels\u Update”,“Customer”))
.Destroy(Destroy=>Destroy.Action(“CustomerViewModels\u Destroy”、“CustomerList”))
)
.Events(Events=>Events.Edit(“onEdit”))
)

我已经实现了这一点,但这也限制了网格将数据发送到服务器。请看代码行below@AjayChaudhary我在代码中添加了一些东西来传递id…我忘记了您需要在创建时传递id…但是模型配置不应该阻止这种形式的发生。
@(Html.Kendo().Grid<MyApplication.Models.CustomerViewModel>()
  .Name("grid")
  .Columns(columns =>
  {
      columns.Bound(c => c.ID).Title("Code");
      columns.Bound(c => c.companyName).Title("Company Name");
      columns.Bound(c => c.address).Title("Address");
      columns.Bound(c => c.addressNumber).Title("Street").Width(60);
      columns.Bound(c => c.zipCode).Title("ZIP Code").Width(60);
      columns.Bound(c => c.city).Title("City").Width(80);
      columns.Bound(c => c.province).Title("Province").Width(45);
  })
  .Editable(editable => editable.Mode(GridEditMode.InCell))
  .Sortable(sortable =>
  {
      sortable.SortMode(GridSortMode.MultipleColumn);
  })
  .Scrollable()
  .HtmlAttributes(new { style = "height: 710px; top: -25px" })
  .ToolBar(toolbar =>
  {
      toolbar.Create();
      toolbar.Save();
      toolbar.Excel();
      toolbar.Pdf();
  })
  .DataSource(dataSource => dataSource
      .Ajax()
       .Model(mdl =>
       {
         mdl.Id("ID");//Tell the grid which field is the id
         mdl.Field(fld => fld.ID).Editable(false);//Make the id field read only
       })
      .Batch(true)
      .Read(read => read.Action("CustomerListViewModels_Read", "Customer"))
      .Create(create => create.Action("CustomerViewModels_Create", "Customer", new { id = "#:data.ID#" }))
      .Update(update => update.Action("CustomerViewModels_Update", "Customer"))
      .Destroy(destroy => destroy.Action("CustomerViewModels_Destroy", "CustomerList"))
  )
 .Events(events => events.Edit("onEdit"))
    )