I have got a view that contain list nad filter options. I need to add option to update selected items on list at once. View with list and filter options looks in short like that:
@model GWeb.Models.FilterModel
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Search criteria</legend>
@Html.LabelFor(model => model.ProjectId, "Project")
@Html.DropDownList("ProjectId",
new SelectList(ViewBag.projectListDesciption as System.Collections.IEnumerable, "Id", "Desciption"), "all")
@Html.LabelFor(model => model.StartWork, "From Date")
@(Html.Telerik().DatePicker()
.Name("StartWork")
.Value(Model.StartWork))
<input type="submit" value="Filter" name="submitButton"/>
</fieldset>
<fieldset>
<legend>Status change</legend>
Change status on selected:
@Html.DropDownList("Status",
new SelectList(ViewBag.statusList as System.Collections.IEnumerable, "Id", "Description"))
<input type="submit" value="Update" name="submitButton"/>
</fieldset>
}
@{Html.RenderPartial("WorkList", Model.workList);}
Where list is rendered in partial view that in short looks like that:
@model IEnumerable<GWeb.Models.WorkModel>
@foreach (var item in Model)
{
<tr>
<td>
@Html.CheckBox("chb" + item.Id, item.Selected)
</td>
...
</tr>
}
Here are models that are used:
public class FilterModel
{
public int ProjectId { get; set; }
public DateTime? StartWork { get; set; }
public int? Status { get; set; }
public List<WorkModel> workList { get; set; }
}
public class WorkModel
{
public int Id { get; set; }
...
public bool Selected { get; set; }
}
In controller I am checking what button was clicked. If it was 'Update' I want to perform modifications. But the workFilter.workList
is always null.
public ActionResult WorkManager(FilterModel workFilter, string submitButton)
{
if (submitButton == "Update")
{
if (workFilter.workList != null)
{
//...
}
}
else
{
//filter
}
//...
return View(workFilter);
How can I check in controller wchich checkbox was selected to update?
Any help much appreciated!