2014-03-28 140 views
0

我想在asp.net mvc的使用剑道UI列表视图添加/编辑

这是我的看法:

<div> 
    <a class="k-button k-button-icontext k-add-button" href="#"><span class="k-icon k-add"></span>Add New Blog</a> 
</div> 
<script type="text/x-kendo-tmpl" id="template"> 
    <div class="product-view k-widget"> 
     <div class="edit-buttons"> 
      <a class="k-button k-button-icontext k-edit-button" href="\\#"><span class="k-icon k-edit"></span></a> 
      <a class="k-button k-button-icontext k-delete-button" href="\\#"><span class="k-icon k-delete"></span></a> 
     </div> 
     <dl> 
      <dt>Subject</dt> 
      <dd>#:Subject#</dd> 

      <dt>Description</dt> 
      <dd>#:Description#</dd> 

      <dt>Address</dt> 
      <dd>#:Address#</dd> 
     </dl> 
    </div> 
</script> 


<div> 
    @(Html.Kendo().ListView<CreateUpdateBlogViewModel>() 
      .Name("UserBlogs") 
      .TagName("div") 
        .ClientTemplateId("template") 
     .DataSource(dataSource => 
     { 
      dataSource.Model(m => 
      { 
       m.Id(i => i.Id); 
       m.Field(f => f.Subject); 
       m.Field(f => f.Address); 
       m.Field(f => f.Description); 
       m.Field(f => f.PageMode).Editable(false); 
      }); 
      dataSource.Read(read => read.Action("UserBlogs_Read", "Webmaster")); 
      dataSource.Update(update => update.Action("Editing_Update", "Webmaster")); 
      dataSource.Destroy(destroy => destroy.Action("Editing_Destroy", "Webmaster")); 
      dataSource.PageSize(1); 
     }) 

      .Pageable().AutoBind(true) 
      .Editable() 
    ) 
</div> 

我的视图模型(CreateUpdateBlogViewModel)已性质(如身份证,CreationDate ,...)我不想向用户展示他们,当他想添加或编辑她的博客 我想用户只需编辑主题说明和地址和其他属性未显示

这怎么办?

只是在显示模式下当前显示这三个属性,当我上添加或编辑按钮,点击视图模型展示,并准备所有财产用于编辑

+0

您是否尝试为非可编辑字段设置可编辑的false。 – Saravanan

+0

是的,但不起作用 –

回答

0

您可以自定义的ListView的编辑模板类似解释here。因此,您可以避免为这些字段创建编辑器。

+0

据此链接:'http://demos.telerik.com/kendo-ui/web/listview/editing.html'不使用编辑器模板,但工作正常 –

+0

我看了你的链接,但不知道在哪里我们将定义的编辑器模板引入到使用它进行添加和编辑的列表视图中吗?可以向我展示一个示例 –

+0

表格很相似,请查看文档[here](http://docs.telerik.com/kendo-ui/getting - 开始/使用剑道与/ aspnet-mvc/helpers/grid/editor-templates)以及关于MVC模板引擎的更多信息,请查看那里给出的链接。 –