0

我一直在努力解决一件小事。我想为模型中的特定字段显示一个复选框。我的观点有一个 IEnumerable 作为@model:

@model IEnumerable<DFIMAX_MVC4.NCSJServices.AxdEntity_LedgerJournalTrans>
@{
    ViewBag.Title = "ledgerJournalTrans";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
    Sagslinjer</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>
<div>
    @{
        var grid = new WebGrid(source: Model, defaultSort: "Name");
        var cols = grid.Columns(
               grid.Column(header: "", style: "ColPost", format: (item) => item.GetSelectLink("Bogfør")),
               grid.Column(header: "", style: "ColDelete", format: (item) => @Html.ActionLink("Slet", "Delete", new { id = item.RecId })),
               grid.Column(header: "", style: "ColEdit", format: (item) => @Html.ActionLink("Ret", "Edit", new { id = item.RecId })),
           grid.Column("NCPosted", style: "ColPosted", header: "Bogført", format: (item) => @Html.CheckBoxFor(item.NCPosted)),
               grid.Column("TransDate", style: "ColDate", header: "Dato", format: (item) => item.TransDate != null
                   ? item.TransDate.ToString("dd-mm-yyyy") : ""),
               grid.Column("NCCaseNumber", style: "ColCase", header: "Sag"),
               grid.Column("Approver", style: "ColInitials", header: "Init."),
               grid.Column("AccountType", style: "ColAccountType", header: "Type"),
               grid.Column("LedgerDimension.DisplayValue", header: "Part/Konto", style: "ColAccount"),
            //grid.Column("Art", header: "Art"),
               grid.Column("Txt", style: "ColTxt", header: "Reference"),
               grid.Column("Voucher", style: "ColVoucher", header: "Bilag"),
            //grid.Column("AmountCurDebit", header: "Debit", format: (item) => string.Format("{0:C}", item.AmountCurDebit)),
            //grid.Column("AmountCurCredit", header: "Kredit", format: (item) => string.Format("{0:C}", item.AmountCurCredit))
               grid.Column(columnName: "Amount", header: "Beløb", style: "ColAmount",
               format: (item) => string.Format("{0:C}", (item.AmountCurDebit != null ? item.AmountCurDebit : 0) - (item.AmountCurCredit != null ? item.AmountCurCredit : 0)))
           );
    }
    @grid.Table(
            columns: cols,
            footer: @<table class="footer">
                <tr>
                    <td class="ColPost">
                        Total
                    </td>
                    <td class="ColDelete">
                    </td>
                    <td class="ColEdit">
                    </td>
                    <td class="ColPosted">
                    </td>
                    <td class="ColApproved">
                    </td>
                    <td class="ColDate">
                    </td>
                    <td class="ColCase">
                    </td>
                    <td class="ColInitials">
                    </td>
                    <td class="ColAccountType">
                    </td>
                    <td class="ColAccount">
                    </td>
                    <td class="ColTxt">
                    </td>
                    <td class="ColVoucher">
                    </td>
                    <td class="ColAmount">
                        Totalbeløb
                    </td>
                </tr>
            </table>,
            tableStyle: "TransListTable",
            headerStyle: "TranslistHeader",
            footerStyle: "TransListFooter",
            alternatingRowStyle: "TransListAlternatingRow",
            selectedRowStyle: "TransListSelectedRow",
            rowStyle: "TransListRow")
</div>

问题是这一行:

grid.Column("NCPosted", style: "ColPosted", header: "Bogført", format: (item) => @Html.CheckBoxFor(item.NCPosted)),

产生的错误是这样的:

编译器错误消息:CS1973:“System.Web.Mvc.HtmlHelper>”没有名为“CheckBoxFor”的适用方法,但似乎具有该名称的扩展方法。扩展方法不能动态调度。考虑强制转换动态参数或在没有扩展方法语法的情况下调用扩展方法。

为什么在我的其他行中,格式: (item) => 有效,但在此复选框上无效?

我也试过:

grid.Column("NCPosted", style: "ColPosted", header: "Bogført", format: (item) => @Html.CheckBoxFor((bool)item.NCPostedValue)),

产生错误的地方是:

编译器错误消息:CS1928:“System.Web.Mvc.HtmlHelper>”不包含“CheckBoxFor”的定义和最佳扩展方法重载“System.Web.Mvc.Html.InputExtensions.CheckBoxFor(System.Web.Mvc. HtmlHelper, System.Linq.Expressions.Expression>)' 有一些无效参数

任何帮助将非常感激。

亲切的问候,

4

2 回答 2

0

好的,试试这个:

format: (item) => InputExtensions.CheckBoxFor(Html, item.NCPosted)
于 2013-06-25T09:06:34.817 回答
0

我想到了:

columns.Add(grid.Column(header: "", style: "ColPost", format: (item) =>
        {
            bool t = ((DFIMAX_MVC4.NCSJServices.AxdEntity_LedgerJournalTrans)item.Value).NCPosted.GetValueOrDefault().Equals(DFIMAX_MVC4.NCSJServices.AxdExtType_JournalPosted.Yes) ? true : false;

            if (((DFIMAX_MVC4.NCSJServices.AxdEntity_LedgerJournalTrans)item.Value).LedgerDimension != null)
            {
                return Html.CheckBoxFor(x => t);
            }
            else
            {
                return "";
            }
        }));
于 2013-06-27T19:15:06.187 回答