Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
hi to all,
Here i want to split the list of string with comma and i need linq query for that

Model:-
XML
public List<string> name{ get; set; }


How to write Linq for above expression;
For below jscript i want to write linq to split string and compare string

here i start like that:-
XML
  public JsonResult name(string names)
        {
                **what i write here**
}
And my script is:
                     $.getJSON('../User/name/' + $('#username').val(), function (data) {
            
            var items = '<option>Select a name</option>';
            $.each(data, function (i, qlist) {
                items += "<option  value='" + qlist.Value + "'>" + qlist.Text + "</option>";
            });
            $('#2nd dropdown').html(items);
Posted
Updated 9-Nov-14 22:43pm
v5

Check this[^]
Split with commas using Linq[^]
Check these links if they help you anyway.
else Post back your queries.
Thanks.:)
 
Share this answer
 
Try like this

C#
public ActionResult name(string names)
       {
           var list = names.Split(',').ToList();
           JavaScriptSerializer serializer = new JavaScriptSerializer();
           var json =  serializer.Serialize(list);
           return Content(json);
       }



XML
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <script src="~/jquery.min.js"></script>
     <script type="text/javascript">

         var getdata = function ()
         {

             $.ajax({
                 type: 'GET',
                 url: '/Home/name/' ,
                 dataType: "json",
                 data: { 'names': $('#username').val() },
                 success: function (data) {
                     var items = '<option>Select a name</option>';
                     $.each(data, function (i, qlist) {
                         debugger;
                         items += "<option  value='" + qlist + "'>" + qlist + "</option>";
                     });
                     $('#2nd').html(items);
                 },
             });
         }


     </script>

    <title>Index</title>
</head>
<body>
    <div>

        <input type="text" id="username" value="apple,bat,cat,dog,eagle" />
        <button onclick="getdata();" > test</button>
        <select id="2nd"></select>
    </div>
</body>
</html>
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 10-Nov-14 7:20am    
here i'm doing this task in mvc 5
Karthik_Mahalingam 10-Nov-14 8:05am    
so what ?
this will work.
or you have anything to ask ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900