我有一个记录表,显示用户完成的活动
我还有与每条记录相关联的复选框,用户可以通过它一次选择多个活动
我想要用户选中复选框的那些记录的ID
我可以显示多条记录,但无法在控制器的发布功能中获得价值
这是我的代码
public ActionResult DisplayList()
{
//do activities to fetch record from database
return View(modelList);//modelList is a viewmodel's Icollection list
}
看法:-
@using (Html.BeginForm())
{
@Html.ValidationSummary(false)
<div style=" width:900px; height:400px;">
<div class="textcontent"><b>List of activities</b></div>
<div class="table" style="vertical-align:middle;">
<div class="row">
<div class="cell" style="width:auto;">SrNo</div>
<div class="cell" style="width:auto;">Select Activity</div>
<div class="cell" style="width:auto;">Learner Name</div>
</div>
@foreach (var item in Model.Select((x, i) => new { Data = x, Index = i + 1 }))
{
<div class="row1">
<div class="cell" style="width:auto;">@item.Index</div>
<div class="cell" style="width:auto;"> <input type="checkbox" name="chkexi" id="selected" onclick="checked()"/></div>
<div class="cell" style="width:auto;">@Html.DisplayFor(modelItem => item.Data.persn.FirstName)</div>
</div>
}
</div>
<div class="table">
<div class="row1">
<div class="cell">
<center>
<button type="submit">Submit</button>//on click of this my controller function is called
</center>
</div>
</div>
</div>
<script>
function checked() {
if (document.getElementById('selected').checked) {
document.getElementById('chkstatus') = true;
}
</script>
}
我的视图模型:::
public class PublishViewModule
{
public virtual myclass obj { get; set; }
public virtual bool chkstatus { get; set; }
}
[HttpPost]
public ActionResult DisplayList(ExhibitionViewModel model,FormCollection form)
{
//here i get model as null
return View();
}
有人可以帮我吗