Guest User

Untitled

a guest
Oct 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. public ActionResult AddCustomerLinkToDB(string IsSeleted)
  2. {
  3. string selectedCustomer = IsSeleted;
  4. return View();
  5. }
  6.  
  7. @using (Html.BeginForm("AddCustomerLinkToDB", "Admin", FormMethod.Post))
  8. {
  9. <table class="table table-bordered table-hover">
  10. <tr>
  11. <th>Customer ID</th>
  12. <th>Customer Name</th>
  13. <th>Select this user</th>
  14. </tr>
  15. @foreach (var item in Model)
  16. {
  17. <tr>
  18. <td>@item.Id</td>
  19. <td>@item.Name</td>
  20. <td>@Html.RadioButton("IsSelected", new { id = item.Id })</td>
  21. </tr>
  22. }
  23. </table>
  24. }
  25.  
  26. public class ViewModel
  27. {
  28. // since the CustID is numeric, I prefer using 'int' property
  29. public int IsSelected { get; set; }
  30.  
  31. public List<Customer> Customers { get; set; }
  32.  
  33. // other properties
  34. }
  35.  
  36. @model ViewModel
  37.  
  38. @using (Html.BeginForm("AddCustomerLinkToDB", "Admin", FormMethod.Post))
  39. {
  40. <table class="table table-bordered table-hover">
  41. <tr>
  42. <th>Customer ID</th>
  43. <th>Customer Name</th>
  44. <th>Select this user</th>
  45. </tr>
  46. @foreach (var item in Model.Customers)
  47. {
  48. <tr>
  49. <td>@item.Id</td>
  50. <td>@item.Name</td>
  51. <td>@Html.RadioButtonFor(model => model.IsSelected, item.Id, new { id = item.Id })</td>
  52. </tr>
  53. }
  54. </table>
  55. }
  56.  
  57. [HttpPost]
  58. public ActionResult AddCustomerLinkToDB(ViewModel model)
  59. {
  60. int selectedCustomer = model.IsSelected;
  61. // other stuff
  62.  
  63. return View();
  64. }
Add Comment
Please, Sign In to add comment