mercredi 1 novembre 2017

How to remove split comma from database and check the checkbox with the checkbox name in mvc

I apolized if title is not clear.

Let first see what I want.

I want to check the multiple checkbox items and save(by split data with comma) and find(by find it will tick the checkbox which is already checked when save the data) from the database in asp.net with mvc.

This task should be done by the checkbox name.

Here is my code that what I tried to insert data of multiple checked items.

Here is the model

public class StaffRegistration
{
    public string WeekEndDay { get; set; }
}

Here is the view

<input type="checkbox" name="checkboxList" value="Monday" />Mon.
<input type="checkbox" name="checkboxList" value="Tuesday" />Tue.
<input type="checkbox" name="checkboxList" value="Wednesday" />Wed.
<input type="checkbox" name="checkboxList" value="Thrusday" />Thr.
<input type="checkbox" name="checkboxList" value="Friday  " />Fri.
<input type="checkbox" name="checkboxList" value="Saturday" />Sat.

Hence it is checkbox, so I check the Monday, Wednesday and Saturday checkbox value and split it by comma on save button click event

Here is the split comma code

$(function () {
    $('#btnSubmit').click(function () {
        var slvals = []
        $('input:checkbox[name=checkboxList]:checked').each(function () {
            slvals.push($(this).val())
        })
    })
});

In slvals variable, checkbox item has store by separating comma i.e. Mon., Wed., Sat. and through by ajax I store in database.

So, in short it can be said that my save function is working perfectly.

Now at fetch time, I store the data i.e. Mon., Wed., Sat., in a variable.

Now how can I remove the comma from the variable and check the checkbox item value in the checkbox with their checkbox name?

Please help me to solve this problem.

Thank You.




Aucun commentaire:

Enregistrer un commentaire