in a MVC C# View I show the records of specifics employees, for that I use MVCScaffolding and the model below
public class Developer
{
public int code { get; set; }
public string areaDev { get; set; }
public string nameDev { get; set; }
public string expDev { get; set; }
public string langDev { get; set; }
}
the view uses razor and for every record there is a checkbox input
@model IEnumerable<WebApplication1.Models.Developer>
@using(Html.BeginForm("ShowRecords","Home"))
{
<table class="table">
<tr>
<th>@Html.DisplayNameFor(model => model.code)</th>
<th>@Html.DisplayNameFor(model => model.areaDev)</th>
<th>@Html.DisplayNameFor(model => model.nameDev)</th>
<th>@Html.DisplayNameFor(model => model.expDev)</th>
<th>@Html.DisplayNameFor(model => model.langDev)</th>
<th>select</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>@Html.DisplayFor(modelItem => item.code)</td>
<td>@Html.DisplayFor(modelItem => item.areaDev)</td>
<td>@Html.DisplayFor(modelItem => item.nameDev)</td>
<td>@Html.DisplayFor(modelItem => item.expDev)</td>
<td>@Html.DisplayFor(modelItem => item.langDev)</td>
<td><input type="checkbox" name="code" value="@item.code" /></td>
</tr>
}
</table>
<input type="submit" value="SEND" />
}
and what I want is to retrieve the information of code(integer code) when the user click the checkbox of one/many specific records displayed in the view,
for that in my controller I receive a int[] as shown below
public ActionResult ShowRecords(int[] datos)
{
{
foreach(var item in datos)
{ ... some code goes here ... }
return View();
}
But I don't receive anything from the view, always receive NULL
could you please help me and tell how to retrieve the code info of the due checked row in my controller?
Edit: just added the isChecked property
public class Developer
{
public int code { get; set; }
public string areaDev { get; set; }
public string nameDev { get; set; }
public string expDev { get; set; }
public string langDev { get; set; }
public bool isChecked { get; set; }
}
the controller that sends info to the view has the new property sets to false(in order to not present the checkbox checked)
while (dr.Read())
{
Models.Developer data = new Models.Developer();
data.code = Convert.ToInt32(dr["code"]);
data.areaDev = dr["areaDev"].ToString();
data.nameDev = dr["nameDev"].ToString();
data.expDev = dr["expDev"].ToString();
data.langDev = dr["langDev"].ToString();
data.isChecked = false;
Records.Add(data);
}
in my View I added this
@Html.CheckBoxFor(modelItem => item.isChecked)
and in the controller I expects to receive a list of developer model
public ActionResult ShowRecords(List<WebApplication1.Models.Developer> datos)
but stills receive NULL