lundi 25 juillet 2016

MVC Razor Grid Losing Checkbox on Paging

Maybe this has to do more with scripting in the dynamic htmlAttribute dictionary, but I have a GridMVC object with paging and I can store the checkstate of a checkbox outside the object, but when I page (let's say from 1 to 6, then go back to 1, it's not saving the state of the checkbox.

I've got an idea I'm trying to get working but I just can't get the syntax correct yet.

Any ideas?

<div>

  @Html.Grid(Model.resultTable).Columns(columns =>
  {
      columns.Add().Encoded(false).Sanitized(false).SetWidth(30).
          RenderValueAs(o => Html.CheckBox("checkrow" + Model.resultTable.IndexOf(o), false, 
          new
          { 
              @onclick = "javascript:toggleRowSelect(" + Model.resultTable.IndexOf(o) + ");", 
              @(ViewBag.selectedTxForReturn.ToString().Contains(o.transaction_no.ToString()) ? "checked" : "")) }));
      //other columns redacted for simplicity = they work
  }).WithPaging(10)

</div>

So the line that's causing the error is:

@(ViewBag.selectedTxForReturn.ToString().Contains(o.transaction_no.ToString()) ? "checked" : ""))

And the error is:

Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.




Aucun commentaire:

Enregistrer un commentaire