关于.NET的一些疑问wGrid.Column()?

时间:2014-03-18 11:17:46

标签: c# asp.net .net asp.net-mvc asp.net-mvc-4

我是 C# .NET (我来自Java)的新手,我对以下视图的工作方式有所怀疑:

@model DataModel.MaliciousCode.SearchMalicious
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/MasterPageMobile.cshtml";

    WebGrid wGrid = new WebGrid(null, rowsPerPage: Model.PageSize, defaultSort: "Published", canPage: false);
    wGrid.Bind(Model.MaliciousCode, rowCount: Model.TotalRows, autoSortAndPage: false);

}

<h2>Index Andrea</h2>

@using (Html.BeginForm("Index", "Malicious", FormMethod.Post, new { id = "MyForm" }))
{

    <div class="ui-field-contain">
        <label for="Filter_Title">Title:</label>
        <input type ="text" data-mini="true" data-clear-btn="true" id="Filter_Title" name="Filter.Title"  value="@Model.Filter.Title"   />
    </div>   

    <div data-role="controlgrup" data-type="horizontal" data-mini="true">
        <input type="reset" data-inline="true" data-mini="true" value="Reset" />
        <input type="submit" data-inline="true" data-mini="true" value="Seach" data-icon="search" />
    </div>
}


pageSize : @Model.PageSize

@if (Model.TotalRows == 0)
{
    <h3>Non è stata trovata nessuna vulnerabilità. Modificare i filtri di ricerca.</h3>
}
else
{


    <div style="margin-top: 20px;">
        <p>TABELLA</p>
        @wGrid.GetHtml(
            fillEmptyRows: false,
            tableStyle: "MyTable ui-responsive",
            headerStyle: "ui-bar-b",
            footerStyle: "ui-bar-b",
            rowStyle: "ui-bar-a",
            alternatingRowStyle: "ui-bar-c",
            htmlAttributes: new { data_role = "table", id = "MyWebGrid", data_mode = "reflow" },
            columns: new[]{

                    wGrid.Column ("Title", "Title", canSort : true),
                    wGrid.Column ("Discovered", "Discovered",  format: p=>p.Discovered.ToShortDateString() ,canSort : true), 

            })

        @{Html.RenderPartial("Paging", Model);}
    </div>
}

正如你在这个视图中看到的,我有一个表,显示集合中的对象(我认为是在我的模型对象中,是试了吗?),这一个:

    @wGrid.GetHtml(
        fillEmptyRows: false,
        tableStyle: "MyTable ui-responsive",
        headerStyle: "ui-bar-b",
        footerStyle: "ui-bar-b",
        rowStyle: "ui-bar-a",
        alternatingRowStyle: "ui-bar-c",
        htmlAttributes: new { data_role = "table", id = "MyWebGrid", data_mode = "reflow" },
        columns: new[]{

                wGrid.Column ("Title", "Title", canSort : true),
                wGrid.Column ("Discovered", "Discovered",  format: p=>p.Discovered.ToShortDateString() ,canSort : true), 

        })

我的怀疑是:

  1. 在这一行中,究竟代表2个字符串:“Title”“Title”作为 wGrid.Coumn()的参数传递方法?

    wGrid.Column(“Title”,“Title”,canSort:true),

  2. 在第二栏中,我还有一个参数:

    wGrid.Column(“已发现”,“已发现”,格式:p =&gt; p.Discovered.ToShortDateString(),canSort:true),

  3. 究竟代表格式:p =&gt; p.Discovered.ToShortDateString()以及什么是p对象?

    TNX

1 个答案:

答案 0 :(得分:3)

  1. 我希望您使用的是Visual Studio。它会在 Ctr + Space 之后按

    显示列方法及其参数的描述
    webGrid.Column(
    

    但你也可以在MSDN中找到描述。如您所见,第一个参数是列名,第二个参数是列标题。

  2. 这是Lamda Expression。在这种情况下,p是WebGrid绑定的任何“行”的对象。