I've been strugling with getting a small thing to work. I want to display a checkbox for a specific field in my model. My view has a IEnumerable as the @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>
The problem is this line:
grid.Column("NCPosted", style: "ColPosted", header: "Bogført", format: (item) => @Html.CheckBoxFor(item.NCPosted)),
The error produced is this:
Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper>' has no applicable method named 'CheckBoxFor' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
Why is it, that on my other lines, the format: (item) => works, but not on this checkbox ?
I have also tried:
grid.Column("NCPosted", style: "ColPosted", header: "Bogført", format: (item) => @Html.CheckBoxFor((bool)item.NCPostedValue)),
Where the error produced is this :
Compiler Error Message: CS1928: 'System.Web.Mvc.HtmlHelper>' does not contain a definition for 'CheckBoxFor' and the best extension method overload 'System.Web.Mvc.Html.InputExtensions.CheckBoxFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>)' has some invalid arguments
Any help would be much appreciated.
Kind regards,