2

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

<tr>
  <td>
    @item
    <input type="hidden" value="@item" name="@item" class="chkbx" id="ControllerName" />
  </td>
  <td>                    
    <input type="checkbox" id="Iscreate" value="@Create" class="chkbx" />
  </td>
  <td>
    <input type="checkbox" id="IsDelete" value="@Delete" class="chkbx" />
  </td>
  <td>
    <input type="checkbox" id="IsView" value="@View" class="chkbx" />
  </td>
  <td>
    <input type="checkbox" id="IsEdit" value="@Edit" class="chkbx" />
  </td>
  <td>
    <input type="checkbox" id="IsDownload" value="@Download" class="chkbx" />
  </td>
</tr>

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();
    }).get().join(',');
    $('#debug').val(vals);
  });
</script>

Basically this code create a Value in hidden Field Like this

3-Create-Account,3-Delete-Account,3-View-Account,3-Edit-Account,3-Download-Account

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

I'm totally Confused :(

6
  • Yes using form collection .I just need to create this value which are defined in post using jquery Commented Jan 24, 2015 at 7:16
  • 2
    OMG. Use a view model and strongly typed html helpers, then post back the model Commented Jan 24, 2015 at 7:20
  • this basically use for create operation date gets from different table and save to different table that's why i use html and i dn't need to use Strongly typed...... Commented Jan 24, 2015 at 7:24
  • Whats that got to do with not doing it the right way? Commented Jan 25, 2015 at 4:28
  • Stephan Muecke Can u help to create this Plz share your skype . Commented Jan 25, 2015 at 8:46

1 Answer 1

2

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 the form to your post action, you will get the values.

[HttpPost]
public ActionResult PostActionName(ViewModelName viewModel)
{
 //use values here
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.