Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:51:07+00:00 2026-05-28T16:51:07+00:00

I am developing an asp.net MVC web app in which I am using Linq

  • 0

I am developing an asp.net MVC web app in which I am using Linq to Sql for getting the results from database through jquery and ajax. My model has following code

 public IEnumerable<string> getComments(long problemID)
        {

            var comment = from c in _objectModel.Comments
                          where c.ProblemID == problemID
                          select new { c.EmpID, c.CommentText, c.Time }.ToString();

            return comment;

        }

and my controller has following code

public string GetComments(string problemid)
        {
            List<string> collection =  _discussionRepository.getComments(Convert.ToInt32(problemid)).ToList();
            string comments = null;
            foreach (string item in collection)
            {
                comments += item + "\n";

            }

            return comments; 



        }

and in my view contains

$("#btnPostComment").click(function () {
  var strdata = {
           problemID: $("#problemID").val(),
           commentText: $("#_1").val(),
           empID: $("#empID").val(),
           agree: 0,
           disagree: 0
        };
        $.ajax({
            type: "POST",
            url: "<%= Url.Action("PostComment", "Discussion")  %>",
            data: strdata,
  error: function(msg){
                alert("error" + msg);
            },
            success: function (msg) {
                var id = { problemid :  $("#problemID").val()};
                 $.ajax({
                    type: "GET",
                    url: "<%= Url.Action("GetComments", "Discussion")  %>",
                    data:  id,
                    error: function(msg){
                         alert("error2" + msg);
                    },
                    success: function (msg) {

                        $("#commentdiv").html(msg);
                    }
                    });


            }
        });

and I am getting the following result in my asp page

{ EmpID = 1, CommentText = sss, Time = 1/27/2012 2:20:49 AM } { EmpID = 1, CommentText = aaa, Time = 1/27/2012 2:46:07 AM } { EmpID = 1, CommentText = aaa, Time = 1/27/2012 2:50:23 AM } { EmpID = 1, CommentText = Munazza, Time = 1/27/2012 2:58:29 AM } { EmpID = 1, CommentText = Jawad, Time = 1/27/2012 3:00:51 AM } { EmpID = 1, CommentText = xx, Time = 1/28/2012 11:56:59 AM } { EmpID = 1, CommentText = ss, Time = 1/28/2012 12:35:00 PM }

I want to get the result without braces and without properties i.e 1 ss 1/27/2012

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:51:07+00:00Added an answer on May 28, 2026 at 4:51 pm

    The problem is that you’re calling ToString on the anonymous type. Does your existing Comment model class contain too much data? If not, you can just use:

    public List<Comment> GetComments(long problemID)
    {
        return _objectModel.Comments.Where(c => c.ProblemID == problemID)
                                    .ToList(); // Force evaluation
    }
    

    You’d then change your controller to convert this List<Comment> into AJAX which the Javascript could understand.

    If you really only want strings without properties, you could just change your original code to:

    public IEnumerable<string> GetComments(long problemID)
    {
        var query = from c in _objectModel.Comments
                    where c.ProblemID == problemID
                    select new { c.EmpID, c.CommentText, c.Time };
    
        return query.AsEnumerable() // Do the rest locally
                    .Select(c => string.Format("{0} {1} {2"}, c.EmpID,
                                               c.CommentText, c.Time));
    }
    

    You should also change your controller code to either use String.Join or a StringBuilder – as otherwise you’re going to have an O(n2) problem due to repeated string concatenation…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an web app using asp.net mvc. I have a List in Cache
I'm developing a web app in asp.net mvc using jquery, the language of application
Does anyone have an experience with developing a big web app using ASP.NET MVC
I am developing asp.net mvc web app with MongoDB as the data storage. I
I'm developing a web application using ASP .NET MVC 1.0 and jQuery (including the
I am using ASP.NET MVC for developing a web site. I am using jquery
I am developing an ASP.NET MVC app and I've been looking into using Data
I am developing a ASP.NET MVC web app under .NET 3.5, NHibernate and hosted
When developing a web app, in my case a ASP.NET MVC app, but this
I'm developing a web application using ASP.NET MVC (I'm new to the framework and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.