0

I want to send multiple selected column values to controller. I don't have issues in sending one column data to controller but having trouble sending more than one column data.

View:

@using (Html.BeginForm("GridView", "Home", FormMethod.Post))
{
    @Html.Grid(Model).Columns(columns =>
    {
        columns.Add()
            .Titled("<input type=checkbox class=ckbCheckAll />")
            .Encoded(false)
            .Sanitized(false)
            .SetWidth(10)
            .RenderValueAs(c => Html.CheckBox("assignChkBx", false, new { @class = "checkBoxClass", value = c.AccountNumber})).SetWidth(10);
        //.RenderValueAs(c => Html.CheckBox("checked", false, new {@class = "checkBoxClass"})).SetWidth(10);
        columns.Add(c => c.AccountNumber).Titled("ACCOUNTNUM").SetWidth(20);
    }).WithPaging(8);

Controller:

[HttpPost]
        public ActionResult GridView(FormCollection form)
    {
        SelectedListOfClaimants slc = new SelectedListOfClaimants();
        var checkbox = form.GetValues("assignChkBx");

        }

In the view where I have value = c.AccountNumber (One of my columns), I need to add two more columns and send all three columns data to my controller.

My view:

Checkbox AccountNumber     Date             Name
   []          1           5/12/2001         John
   []          2           5/10/2003          Paul
   []          3           5/11/2018          Tom
Swas
  • 1
  • 1
  • Since you're going to be sending in possible multiple objects... a list might be what you need. So in your controller method `GridView`... instead of just `FormCollection`, make it a `List` and then go from there. – jPhizzle Jul 02 '19 at 23:34
  • @jPhizzle, I'm getting form value as null if I make it a list in my controller method. Also, I need to change my "value" in Html.checkbox as well as I just have one column in my value. – Swas Jul 03 '19 at 01:45
  • since you're passing in a list, you might need to change the functionality of your controller method. try a foreach loop :) – jPhizzle Jul 03 '19 at 14:53

0 Answers0