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 8700133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:07:01+00:00 2026-06-13T02:07:01+00:00

I have method to retrieve data from DAL as follows: public List<Comment> GetAllComment(int _UserID)

  • 0

I have method to retrieve data from DAL as follows:

public List<Comment> GetAllComment(int _UserID)
    {
        using (var context = new TourBlogEntities1())
        {
            var AllComment = from s in context.Comments
                             where s.UserID == _UserID
                             select s;

            return AllComment.ToList<Comment>();
        }
    }

Now I’m trying to call this method from my controller as follwos:

[HttpPost]
    public ActionResult NewComment(PostComment model)
    {
        var business = new Business();

        var entity = new Comment();
        entity.Comments = model.Comments.Comments;
        //entity.PostID = model.Posts.PostID; HOW TO PASS POSTID???
        entity.UserID = business.GetUserID(User.Identity.Name);

        business.PostComment(entity);

        var CommentsListFromEntity = business.GetAllComment(business.GetUserID(User.Identity.Name));

        var viewmodel = new PostComment();
        viewmodel.CommentsListFromModel = CommentsListFromEntity.ToList<CommentInfo>(); // Error is showing here  

        return View("ViewPost", viewmodel);
    }

I bind my view with the model, but could not use the list, Even if I try to pass the list itself to view, still I can’t use that list in view!

My model class is as follows:

public class PostComment
{
    public PostComment()
    {
        Posts = new NewPost();
        Comments = new CommentInfo();
        User = new UserInfoModel();
    }

    public NewPost Posts { get; set; }
    public CommentInfo Comments { get; set; }
    public UserInfoModel User { get; set; }
    public List<CommentInfo> CommentsListFromModel { get; set; }

}

So how to use the list in view? I need the help badly!

  • 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-06-13T02:07:03+00:00Added an answer on June 13, 2026 at 2:07 am

    You need to return an ActionResult from controller actions:

    public ActionResult GetAllComment(int _UserID)
    {
        using (var context = new TourBlogEntities1())
        {
            var AllComment = from s in context.Comments
                             where s.UserID == _UserID
                             select s;
    
            return View(AllComment.ToList());
        }
    }
    

    Now the corresponding view could be strongly typed to List<Comment>:

    @model List<Comment
    

    and then you could loop through the model and display it:

    @foreach (var comment in Model) 
    {
        <div><@comment.Text</div>
    }
    

    UPDATE:

    If this method is in your BLL you could invoke it in your controller action and pass the result to the view:

    public ActionResult SomeAction(int userID)
    {
        List<Comment> comments = bll.GetAllComment(userID);
        return View(comments);
    }
    

    UPDATE 2:

    If you need to pass other properties to the view in addition to this list then you define a view model containing all the necessary information:

    public class MyViewModel
    {
        public List<Comment> Comments { get; set; }
        public string Foo { get; set; }
        public string Bar { get; set; }
        ...
    }
    

    and then have your controller action pass this view model to the view:

    public ActionResult SomeAction(int userID)
    {
        var model = new MyViewModel();
        model.Comments = bll.GetAllComment(userID);
        model.Foo = "that's the foo";
        model.Bar = "that's the bar";
        return View(model);
    }
    

    and finally your view is strongly typed to the new view model:

    @model MyViewModel
    
    <h2>@Html.DisplayFor(x => x.Foo)</h2>
    
    @foreach (var comment in Model.Comments)
    {
        <div>@comment.Text</div>
    }
    
    <span>@Html.DisplayFor(x => x.Bar)</span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrieve data from a POST method, code as follows: -(void)postXMLFeed:(NSString *)XMLStrPost
I want to retrieve data from server using HTTP POST method for my iphone
Hello I have the following code to retrieve data from my db using nhibernate
I am trying to retrieve some data from a database using jQuery's $.getJSON method
I have learnt how to create a HTTP Get request method to retrieve data
I am wondering which is a more efficent method to retrieve data from the
I am using GWT RPC & Hibernate to insert and retrieve data from MySql
I am using GWT RPC & Hibernate to insert and retrieve data from MySQL
I 'm trying to retrieve data from a datastore by using this (in example)
I have a project with ASP.NET MVC, using Entity Framework to get data from

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.