samedi 24 septembre 2016

Checkbox does not change the value of view model

I'm using check box to show values of a table but I can't link my check boxes to my view model. Also, I don't want to use @EditorFor or @CheckboxFor because those two create two checkboxes and my code passes the value of check box in the link so it passes two and the link gets ugly.

Some other things I would like to do:

I would like my table to be updated the instant there is an action on check boxes but I don't know how.

I want my check box to retain it's value (I'm using this with pagination)

A few things I found out after debugging:

Check boxes value is set to false and can't be changed even though it's set to be "true" on default.

I'm not sure if the problem is I can't connect my checkbox to view model OR It is linked but I can't change the value.

View Model

public bool admin { get; set; }

public bool user { get; set; }

public bool supplier { get; set; }

@using (Html.BeginForm("Index", "AdminAccounts", FormMethod.Get))
{

    <input type="checkbox" name="admin" id="admin" value="true" @Model.admin/> Admin
    <input type="checkbox" name="user" id="user" value="true" @Model.user/> User
    <input type="checkbox" name="supplier" id="supplier" value="true" @Model.supplier/> Supplier

Controller:

if(vm.admin==true)
            {
               ///code here
            }




Aucun commentaire:

Enregistrer un commentaire