Hi bigbear,
You need to make ajax call to passs the model value to Controller.
Refer below example.
Controller
public class CustomerModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public string Gender { get; set; }
}
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
List<CustomerModel> customers = new List<CustomerModel>();
customers.Add(new CustomerModel { Id = 1, Name = "John Hammond", Country = "United States", Gender = "Male" });
customers.Add(new CustomerModel { Id = 2, Name = "Mudassar Khan", Country = "India", Gender = "Male" });
customers.Add(new CustomerModel { Id = 3, Name = "Suzanne Mathews", Country = "France", Gender = "Female" });
customers.Add(new CustomerModel { Id = 4, Name = "Robert Schidner", Country = "Russia", Gender = "Male" });
return View(customers);
}
[HttpPost]
public IActionResult Index(CustomerModel model)
{
if (model?.Id != 0)
{
return View("UpdatePickQuantity", model);
}
return View();
}
}
View
@model List<RadioButton_Model_Core_MVC.Models.CustomerModel>
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<form>
<div id="tblPullParts" class="container justify-content-center mt-3">
<table id="tblCustomers" class="table table-striped">
<thead>
<tr>
<th></th>
<th>Id</th>
<th>Name</th>
<th>Country</th>
</tr>
</thead>
<tbody>
@foreach (var customer in Model)
{
<tr>
<td>
<input id="@customer.Id" type="radio" name="customer" value="@customer.Id" />
<label for="@customer.Id">@customer.Gender</label>
</td>
<td>@Html.DisplayFor(item => customer.Id)</td>
<td>@Html.DisplayFor(item => customer.Name)</td>
<td>@Html.DisplayFor(item => customer.Country)</td>
</tr>
}
</tbody>
</table>
</div>
<div class="text-center">
<button id="btnSubmit" type="button" class="btn btn-lg btn-success mt-3">Start Pick</button>
</div>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("body").on("click", "#btnSubmit", function () {
var customer = {};
$("#tblCustomers TBODY TR").each(function () {
var row = $(this);
if (row.find("input[type=radio]").attr('checked') == "checked") {
customer.Name = row.find("TD").eq(2).html();
customer.Country = row.find("TD").eq(3).html();
}
});
$.ajax({
type: "POST",
url: "/Home/Index",
data: { model: customer },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r + " record(s) inserted.");
}
});
});
});
</script>
</body>
</html>
Screenshots
The Form
Value in Controller