In my application, it displays a certain amount of items depending on each user. Let's just say, a user logs in and see 3 books and there are radio buttons for each item that indicate "Buy" or "Rent" that they can choose or populates preset value already selected. I've assigned the value true or false for each radio button.
So here, I'm trying to POST the value of each radio button, but I'm not getting anything back from the radio buttons when I step through. Everything else comes back except the value from the radio buttons. I've tried "FormCollection", Retrieving from the ViewModel and Request.Form[], but none work.
Down below is a sample code:
ViewModel
public class CustomerBooksViewModel
{
public int? ID {get; set;}
public int? CustomerID {get;set;}
public string Title {get;set;}
public string Author {get;set;}
public string ISBN {get;set;}
public bool? BuyRent{get;set;}
}
Controller - Request.Form Example
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Update()
{
var ItemCustomerID = Request.Form["item.CustomerID"];
var ItemTitle = Request.Form["item.Title "];
var ItemAuthor = Request.Form["item.Author "];
var ItemISBN = Request.Form["item.ISBN "];
var ItemBuyRent = Request.Form["item.BuyRent"];
}
View - (Just a sample for the radio buttons)
@using(Html.BeginForm("Update", "CustomerBooks", FormMethod.Post))
{
@Html.AntiForgeryToken()
@foreach (...)
{
...
<td>
@Html.RadioButtonFor(modelItem => item.BuyRent, true, new{ @Name = "", id=""})) Buy
@Html.RadioButtonFor(modelItem => item.BuyRent, false, new{ @Name = "", id = ""})) Rent
</td>
...
}
}