1

I am having list of skills on my Registration page like:

playing,Dancing,Programming etc.

 public partial class EmployeeMaster
 {
    public int Id { get; set; }
    public string Fullname { get; set; }
    public string Skills { get; set; }
 }

Now on my post method i am receiving Skills like this:

This skill is a list object:listSkill object:

[0]:Name=Playing
   Selected=true

[1]:Name=Dancing
   Selected=true

[2]:Name=Programming
   Selected=false

[HttpPost]
    public ActionResult Index(EmployeeModel m)
    {
        if (ModelState.IsValid)
        {
            var employeeModel = new EmployeeMaster();
            employeeModel.Skills = m.Skills.Select(t => t.Name).SingleOrDefault();  //How to do this as this would take only single value not all skills?

I want to concatinate all this skills in to a single string seperated by comma and store in my database table.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
I Love Stackoverflow
  • 6,738
  • 20
  • 97
  • 216

2 Answers2

3

Simply by using string.Join with your desired Skills property (Name in this case):

employeeModel.Skills = string.Join(", ", m.Skills.Select(t => t.Name));

This will concatenate all your skill names using the ", " separator.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
1
employeeModel.Skills = string.Join(",", m.Skills.Select(t => t.Name).Distinct().ToList()); 

my suggestion use like this very helpful to you.

Shahzad Khan
  • 432
  • 2
  • 14