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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:03:00+00:00 2026-06-18T09:03:00+00:00

I have a search page which allows users to search for an item and

  • 0

I have a search page which allows users to search for an item and add details to an item. I am working on allowing users to apply the same details to several items. The user will check all the items he would like to apply the same changes to and click a Comment button. This will send a list of items checked List<int> ids and the particular item clicked (to use as template in case it already exists) int id.

From here the user will edit the comment however he wishes and save. How will the HttpPost Edit action look? It is required to add a comment to the database if it doesn’t exist for that item already, otherwise, overwrite what exists. Below is what I have come up with (basic outline). The problem I see with this is that it requires poking the database for every item I want the changes applied to. There has to be a better way to do this.

[HttpPost]
public ActionResult Edit(CommentVM model)
{
    if (ModelState.IsValid)
    {
        foreach(int i in model.ids)
        {
            Comment comment = _db.Comments.Find(i);
            if(comment == null){
                //Create and add
            {
            else{
                comment.Text = model.Text;
                _db.Entry(comment).State = EntityState.Modified;
            }
        }

        _db.SaveChanges();
        return RedirectToAction("Index");
    }
    return View(model);
}
  • 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-18T09:03:01+00:00Added an answer on June 18, 2026 at 9:03 am

    I ended up using a sort of homebrew method. Since both cases (add entry and edit entry needed to be handled separately, I handled them as such.

    List<int> InDB = _db.Comments           
        .Where(r => model.ids.Contains(r.id))
        .Select(r => r.id)
        .ToList();
    
    List<int> diff = model.ids.Except(InDB).ToList();
    //Loop through items to ADD
    foreach (int i in diff)
    {
        Comment comment = new Comment { Text = model.Text, id = i };
        _db.Comments.Add(comment);
    }
    //Loop through items to edit
    foreach (int i in InDB)
    {
        Comment comment = new Comment { Text = model.Text, id = i };
        _db.Entry(comment).State = EntityState.Modified;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search page which allows users to further filter thier results based
Currently i have a working PHP edit script, which allows users to edit ads
I have a search page which uses a simple ajax request to get new
I have the following scenario. I have a search page which is split into
I have a search page in which I am searching data by passing multiple
I have xpath page.search(//table[@class='campaign']//table) which returns two tables. I need to choose only first
I have an html page called search.html which contains sliders, they work perfectly in
I have a text box which allows a user to search for content on
I have a website which allows users to submit photos of wildlife. Once uploaded,
I have a master page that contains a search box which is validated as

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.