Hi i done my self.. please refer below code.
in controller
------------------------------------
public ActionResult Index()
{
var players = new List<player>
{
new Player {Id = "101", Rank = 1, Name = "Sai", Country = "NOR", Points = 16},
new Player {Id = "102", Rank = 2, Name = "sagar", Country = "RUS", Points = 14},
new Player {Id = "103", Rank = 3, Name = "sai sagar", Country = "SWE", Points = 13},
new Player {Id = "104", Rank = 4, Name = "yash", Country = "USA", Points = 12},
new Player {Id = "105", Rank = 5, Name = "Anil", Country = "SWE", Points = 11},
new Player {Id = "106", Rank = 6, Name = "Ravi", Country = "NOR", Points = 11},
new Player {Id = "107", Rank = 7, Name = "pradep", Country = "CAN", Points = 11},
new Player {Id = "108", Rank = 8, Name = "sai", Country = "FIN", Points = 9},
new Player {Id = "109", Rank = 8, Name = "sagar", Country = "CAN", Points = 9},
new Player {Id = "110", Rank = 10,Name = "Paul", Country = "USA", Points = 9}
};
ViewData["SelectList"] = HttpContext.Session["SelectList"] ?? new List<string>();
return View(players);
}
[HttpPost]
public ActionResult Select(bool isChecked, String id)
{
var selectList = (List<string>)HttpContext.Session["SelectList"] ?? new List<string>();
if (isChecked && !selectList.Contains(id))
{
selectList.Add(id);
}
else if (!isChecked && selectList.Contains(id))
{
selectList.RemoveAll(s => s == id);
}
HttpContext.Session["SelectList"] = selectList;
return Content("OK");
}
----------------------------
in view
@model IEnumerable your modelname
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery-ui-1.8.20.js"></script>
<script src="~/Scripts/knockout-2.1.0.js"></script>
<script type="text/javascript">
$(function () {
$(':checkbox').change(function () {
$.ajax({
url: '@Url.Action("Select")',
type: 'POST',
data: { isChecked: $(this).is(':checked'), id: $(this).val() },
success: function (result) {
}
});
});
});
</script>
@{
var grid = new WebGrid(source: Model,
defaultSort: "Rank",
canSort: true,
rowsPerPage: 5
);
}
@grid.GetHtml(
tableStyle: "grid",
headerStyle: "head",
alternatingRowStyle: "alt",
columns: grid.Columns(
grid.Column("Select", format: @<text><input name="Id" type="checkbox" value="@item.Id" @Html.Raw(((List<string>)ViewData["SelectList"]).Contains(@item.Id) ? "checked" : "") />),
grid.Column("Rank", "Rank"),
grid.Column("Name", "Name"),
grid.Column("Country", "Country"),
grid.Column("Points", "Points")
)
)
in model
public class Player
{
public String Id { get; set; }
public int Rank { get; set; }
public String Name { get; set; }
public String Country { get; set; }
public int Points { get; set; }
}