Question

I have a view model that looks like this

 public class ViewModelRound2 
    {
        public Bid Bid { get; set; }
        public bool SelectedForRound2 { get; set; }  
    }

I have a get action method that looks like this

public ActionResult Round2Manager(long id)
        {
            ...

            return View(round1Ring3Bids);
        }

And a post method that looks like this (not implemented it yet)

[HttpPost]
        public ActionResult Round2Manager(IEnumerable<ViewModelRound2> viewModelRound2)
        {
            return View(viewModelRound2);
        }

My view looks like this

   @for (var x = 0; x < Model.Count(); x++)
    {
        ViewModelRound2 viewModelRound2 = Model.ElementAt(x);
        Bid bid = viewModelRound2.Bid;

        string userName = @bid.User.Invitation.Where(i => i.AuctionId == bid.Lot.Lot_Auction_ID).First().User.User_Username;

        <tr>
            <td>
                @userName
            </td>
            <td>
                @bid.Bid_Value
            </td>
            <td>
                @Html.EditorFor(c => c.ElementAt(x).SelectedForRound2) 
            </td>
        </tr>
    }

</table>

<div class="buttonwrapper2">
    @Ajax.ActionLink("Select", "Round2Manager", new { viewModelRound2 = Model }, new AjaxOptions() { HttpMethod = "POST"} )
</div>

The page this renders, contains checkboxes per row in the rendered table and I want to be able to pass checked/unchecked values to the post method so that it can process them. The problem is that the viewModelRound2 parameter of the post method is always null. What is going on? How can I write this so that it does what I intend?

Was it helpful?

Solution

You should put all that HTML inside a <form>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top