---
title: "How to get checked value of checkbox in  MVC 4"  
description: "How to get checked value of checkbox in  MVC 4"  
author: "Royce Roy"  
published: 2013-02-02  
updated: 2013-02-02  
canonical: https://www.mindstick.com/forum/569/how-to-get-checked-value-of-checkbox-in-mvc-4  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# How to get checked value of checkbox in  MVC 4

Hi Everyone!\
I have created dynamicaly [checkbox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) in [partial view](https://www.mindstick.com/articles/1132/auto-refresh-partial-view-in-asp-dot-net-mvc) in MVC 4. How to get checked value of checkbox in [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) when form post. Dynamicaly generated checkbox code as below

@using ([Html.BeginForm](https://www.mindstick.com/forum/1944/html-beginform-post-going-to-httpget-action-rather-than-httppost-in-ie-fine-in-chrome-and-firefox)("AttachmentList", "Home", FormMethod.Post, new\
{\
@id = "PDFListDownload"\
}))\
{\
<div id="PDFAttachmentList">\
<table>\
@[foreach](https://www.mindstick.com/forum/33870/how-parallel-foreach-works-internally) (var item in Model)\
{\
<tr>\
<td>@Html.CheckBox("fileItem")\
@Html.Hidden("fileId", item.AtttachmentID)\
</td>\
<td>@Html.DisplayTextFor(m => item.Description)\
</td>\
</tr>\
}\
<tr>\
<td>\
<input id="btnDownload" type="submit" value="[Download](https://www.mindstick.com/articles/188403/website-to-download-photos-from-instagram)" />\
</td>\
<td>\
<input id="btnCancel" type="[button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net)" value="[Cancel](https://answers.mindstick.com/qa/94501/how-can-i-cancel-my-singapore-flight-ticket)" [onclick](https://www.mindstick.com/forum/12718/onclick-for-hyperlink)="CloseDialog();" />\
</td>\
</tr>\
</table>\
</div>\
}

Thanks and regard!

## Replies

### Reply by AVADHESH PATEL

Hi Royce Roy!

Post your View or [Partial](https://www.mindstick.com/blog/78/partial-class-in-dot-net) View to Action as below code and identify which checkbox are checked based on Hidden field ID(acording your code).

```
[HttpPost]        public ActionResult AttachmentList(FormCollection formData)        {            var fileIds = formData["fileId"].Split(',');            var selectedIndices = formData["fileItem"].Replace("true,false", "true").Split(',').Select((item, index) => new            {                item = item,                index = index            }).Where(row => row.item == "true").Select(row => row.index).ToArray();            if (selectedIndices.Count() > 0)            {  foreach (var index in selectedIndices)                {   int checkedID = fileIds[index]; // Here "CheckedID" is checked checkbox id. You can populate condition according this value.  }     } }
```


---

Original Source: https://www.mindstick.com/forum/569/how-to-get-checked-value-of-checkbox-in-mvc-4

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
