joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
75 stars 56 forks source link

Need a way to add hidden inputs per row for a checkbox #168

Open SCPrior opened 6 years ago

SCPrior commented 6 years ago

I'm trying to add a column with a checkbox (which I have managed with the ValueTemplate function), but I'm unable to add the required hidden inputs for the purposes of posting back the details of the items that have been checked. I need the html to look like this:

<input type="hidden" name="checkedItems[0].Index" value="0" />, which needs to occur once above the below examples, so that the default binder knows to post back an array of objects.

Row 1 - Checkbox Cell `

<input type="hidden" name="checkedItems[0].ListOfSomething[0].Field1" value="somevalue" ) /> <input type="hidden" name="checkedItems[0].ListOfSomething[0].Field2" value="somevalue" ) /> <input type="hidden" name="checkedItems[0].ListOfSomething[0].Field3" value="somevalue" ) /> <input type="hidden" name="checkedItems[0].ListOfSomething[1].Field1" value="somevalue" ) /> <input type="hidden" name="checkedItems[0].ListOfSomething[1].Field2" value="somevalue" ) /> <input type="hidden" name="checkedItems[0].ListOfSomething[1].Field3" value="somevalue" ) />`

Row 2 - Checkbox Cell `

<input type="hidden" name="checkedItems[1].ListOfSomething[0].Field1" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[0].Field2" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[0].Field3" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[1].Field1" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[1].Field2" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[1].Field3" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[2].Field1" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[2].Field2" value="someothervalue" ) /> <input type="hidden" name="checkedItems[1].ListOfSomething[2].Field3" value="someothervalue" ) />`

Row N - Checkbox Cell And so on with the index being incremented by 1 per row.

My Model public class Something { public string Field1 { get; set; } public string Field2 { get; set; } public string Field3 { get; set; } }

public class MyModel { public bool Selected { get; set; } public string Field1 { get; set; } public string Field2 { get; set; }
public List { get; set; } }

Any advice on how to achieve this would be appreciated. Thanks.

SCPrior commented 6 years ago

An amendment to my previous post:

public class MyModel { public bool Selected { get; set; } public string Field1 { get; set; } public string Field2 { get; set; } public List ListOfSomething { get; set; } }