Home > DeveloperSection > Forums > How to get checkbox value in Asp.net mvc?`
ben reitman
ben reitman

Total Post:96

Posted on    April-14-2015 12:51 AM

 ASP.NET MVC Mvc  Mvc4 

 1 Reply(s)
 1244  View(s)
Rate this:

I'm creating a table.I want to get selected checkbox value.




    <input type="hidden" value="@item" name="@item" class="chkbx" id="ControllerName" />



    <input type="checkbox" id="Iscreate" value="@Create" class="chkbx" />



    <input type="checkbox" id="IsDelete" value="@Delete" class="chkbx" />



    <input type="checkbox" id="IsView" value="@View" class="chkbx" />



    <input type="checkbox" id="IsEdit" value="@Edit" class="chkbx" />



    <input type="checkbox" id="IsDownload" value="@Download" class="chkbx" />



Jquery code I use

<script type="text/javascript">

  $('input[type=checkbox]').change(function () {

    var vales = $("#ControllerName").val();

    var vals = $('input[class=chkbx]:checked').map(function () {

      return $(this).val();





Basically this code create a Value in hidden Field Like this


But Actually i need this

3-Account-Create-Delete-Edit-Download-view,4-Account-Create-Delete-Edit-Download-view, 5-Account-Create-Delete-Edit-Download-view

Brad Pitt
Brad Pitt

Total Post:61

Posted on    April-14-2015 2:18 AM

Make a view model with your wanted properties:

public class YouViewModelName()


    public bool IsView {get; set;}

    public bool IsDeleted{get; set;}

    public bool IsCreated{get; set;}

    public bool IsEdited{get; set;}

    ......... and so on


Then use this view model in your view:


@Html.CheckBoxFor(x => x.IsView)

@Html.CheckBoxFor(x => x.IsDeleted)

@Html.CheckBoxFor(x => x.IsCreated)

@Html.CheckBoxFor(x => x.IsEdited)

and so on...


When you post that view to your post action, you will get the values.



public ActionResult PostActionName(ViewModelName viewModel)


 //use values here


Don't want to miss updates? Please click the below button!

Follow MindStick