How to save Checboxes values into single column?
I have a view which has a few checkboxes in mvc. i designed them in html inside view. Now I require to save the selected values of checkboxes into a single column of a table.
If there are multiple checbox values, I need to save values with comma separator in that column. Please help
20 Replies
If you have a list of your selected values you could join them
e.g.
oh nice.may I know how to get checkboxes values as list.coz I am using 6 separate checkboxes inside Create View along with other inputs. I designed in html the checkboxes. Could you guide a little more
I M using a single Employess table(I'd, Name, Dept, sex, sports) in database.
I m using efcore db first approach.
Only one table Employee.
Without code I cant help you a lot.
But I assue you could do a onchange event listener.
Which would call a function like AddToList(ChangeEventArgs cea)
then you could take the value from the event argument like this
and then just yourList.Add(value);
oh ok I will try
already I wrote a onclick js fn and have it inside wwwroot/JS
like just a onclick for inside submit control to catch the particular checked checkbox value and spit out alert message.
But that fn not get called
what do you use as frontend ?
mvc
razor with html combined
I don't think you have to write any js for this. in razor you have attributes like @bind-value or @onchange to call the functions.
oh i see
razor seems tough:(
checkboxes I designed in html.will that works?
you mean in your razor page?
yes yes
yes it will work
oh ok ok
there are also ui frameworks that would make your life easier like radzen. But I would first learn how to implement this by yourself, just to understand it before using libraries
oh awesome
is radzen free to use?
yes there is a community license which you can use
oh ok ok.sure.but my lead asked me to do this in razor and html now.anyways I will try
thanks now..right now I m home 🙂
no problem:)
thanks for your time
no problem^^
no emoji loading.so I am typing my thumb up in reply:)
thumbs up
@jmb friend that's fixed.
Now I hv
another issue.
i hv created two tables and created keys
Table 1: Employee Tabke(ID(pk), Name, Address)
Table 2: EmployeePersonalTable( Id(fk),Phone Number, PIN)
Entity First db
Created keys on both tables and designed ui in view.Did code in controller.
Created a view model to hold two models and tried to push it into db.
However, error show up that second Table I'd can't be traced since it is not primary key.
However, I created fk on I'd field.Please