简体   繁体   English

如何在 cshtml.cs 中获取列表

[英]How can I Get a List in cshtml.cs

I'm using a razor pages.我正在使用 razor 页面。 I have on list of permissions, and this list have prop of treeview.我有权限列表,这个列表有 treeview 的道具。

permissions.Add(new Paccess { id = "All", name = "Acesso Total", expanded = true, haschildren = true, ischecked = true });
permissions.Add(new Paccess { id = "G", name = "Geral", expanded = false, haschildren = false, ischecked = true, parent = "All" });
permissions.Add(new Paccess { id = "U", name = "Gestão de Utilizadores", expanded = false, haschildren = false, ischecked = true, parent = "All" });
permissions.Add(new Paccess { id = "E", name = "Gestão de Equipamentos", expanded = false, haschildren = false, ischecked = true, parent = "All" });

In my cshtml I have this treeView在我的 cshtml 中,我有这个 treeView

<ejs-dialog id="default_dialog" isModal="true" width="500px" visible="false" showCloseIcon="true" header="Acessos">
    <e-content-template>
        <form method="post" style="padding:1em">
            <ejs-treeview id="listdata" name="permissions" TValue="Paccess" showCheckBox="true" nodeClicked="nodeCheck" autoCheck="true">
                <e-treeview-fields TValue="Paccess" dataSource="@Model.permissions" text="name" name="permissions" id="id" parentId="parent" hasChildren="haschildren" expanded="expanded" IsChecked="ischecked"></e-treeview-fields>
            </ejs-treeview>
            <button class="button special pull-right" asp-page-handler="Save">Teste</button>
        </form>                            
    </e-content-template>
</ejs-dialog>

I want, when I click in Teste, get the list in my cshtml.cs.我想,当我点击 Teste 时,在我的 cshtml.cs 中获取列表。


Paccess class:帕克西斯 class:

public class Paccess 
{
    public string? id { get; set; } 
    public string? name { get; set; } 
    public bool haschildren { get; set; } 
    public string? parent { get; set; } 
    public bool expanded { get; set; } 
    public bool ischecked { get; set; } 
}

In TreeView, we have getTreeData method which will retrieve the updated data source of TreeView. If you pass the ID of TreeView node as arguments for this method, then it will return the updated data source of the corresponding node otherwise it will return the entire updated data source of TreeView. Check the below code snippet.在TreeView中,我们有getTreeData方法,它会获取TreeView的更新数据源。如果将TreeView节点的ID作为arguments传递给该方法,则返回对应节点的更新数据源,否则返回整个更新数据源TreeView 的数据源。检查下面的代码片段。

<button class="button special pull-right" id="normalbtn" asp-page-handler="Save">Teste</button>
...
document.getElementById('normalbtn').onclick = function () {
    var treeview = document.getElementById("listdata").ej2_instances[0];
    //Here you can get the updated datasource.
    var data = treeview.getTreeData();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从CSHTML.CS页面操作DOM? - How do I manipulate the DOM from the CSHTML.CS page? cshtml.cs 中的换行符 - Line Break in cshtml.cs 如何在.cshtml中显示与.cshtml.cs中的值相对应的数据库值(剃须刀页面) - How to display database values in .cshtml corresponding to values in .cshtml.cs (razor pages) 使用模型将函数从cshtml调用到cshtml.cs - Call function from cshtml to cshtml.cs using Models 将参数从cshtml解析为cshtml.cs中的操作 - Parsing Parameter from cshtml to an action in cshtml.cs C#、Blazor、VS:如何抑制所有 *.razor.cs 和 *.cshtml.cs 文件的 IDE0051 和 IDE0052? - C#, Blazor, VS: How to suppress IDE0051 and IDE0052 for all *.razor.cs and *.cshtml.cs files? user.FirstName in.cshtml.cs 文件为 null - user.FirstName in .cshtml.cs file is null 使用 PageModel 将 HTML 表信息从 cshtml 传递到 onpost cshtml.cs 方法 - Passing HTML table information from cshtml to method onpost cshtml.cs using PageModel 是否可以在设置页面上的 .cshtml.cs 文件中执行 OnPost() 方法之前执行特定的代码块? - Is it possible to execute a specific block of code before the OnPost() method is executed in the .cshtml.cs file on a set pages? 如何从 register.cshtml 和 register.cshtml.cs 中的 AspNetRoles 表中构建下拉列表? - how to Build drop-down list from AspNetRoles table in register.cshtml and register.cshtml.cs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM