I was looking around and trying to find a solution for my problem, but somehow I can not find the right answer.
I have an Index.cshtml view that looks like this:
@model IEnumerable<MyProject.Models.Conditions>
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm())
{
<style> ... </style>
<div class="container1">
<div class="box1">
<div class="box-cell1 box1">
<fieldset id="field1">
<legend>CustomerNumber</legend>
@Html.TextBox("s_custNum")
<input type="submit" value=">" style="height: 22px; width: 50px; padding:0px;" />
</fieldset>
</div>
</div>
</div>
<table class="tableMain" id="x">
<tr class="trMain">
<th class="thMain">
@Html.DisplayNameFor(model => model.ID)
</th>
<th class="thMain">
@Html.DisplayNameFor(model => model.NAME)
</th>
<th class="thMain">
@Html.ActionLink("Edit Lines", "EditAll", "EditAll", null)
</th>
</tr>
@foreach (var item in Model)
{
<tr class="trMain">
<td class="tdMain">
@Html.DisplayFor(modelItem => item.ID)
</td>
<td class="tdMain">
@Html.DisplayFor(modelItem => item.NAME)
</td>
<td class="tdMain">
<input type="checkbox" class="chkCheckBoxId" name="custId" value="@item.ID" />
</td>
</tr>
}
</table>
I'm currently listing all records as table on my site and each record has a checkbox. The header has an action link for redirecting the user to a new editing site. At the top of the site is a search Textbox.
The method in my controller looks like this:
[HttpPost]
public ActionResult EditAll(FormCollection collection)
{
var test = Request.Form.GetValues("custId");
string[] ids = collection["custId"].Split(new char[] { ',' });
return View();
}
Here I'm trying to get all the ids from the records that are checked. However, I get an error 404 that the page can not be found. When I remove the [HttpPost] attribute, the method gets called but returns no values in "test" or "ids".
I even tried to add values to my Html.BeginForm, but then the searchbar on the site does not work anymore.
Could someone help me retrieving the ids of the checked records? I'm new to ASP.NET MVC.
Many thanks!