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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:37:31+00:00 2026-06-08T07:37:31+00:00

I have an Object public class Object1{ public List<Object2> {get;set;} } public class Object2{

  • 0

I have an Object

public class Object1{
public List<Object2> {get;set;}
}


public class Object2{
public Name{get;set;}
public Address{get;set;}
}

I have a feature where the user can update just one instance of Object2. So my code for saving Object2 looks like

[HttpPost]
public ActionResult SaveObject2(Object2 obj2)
{
  if (obj2.Id == null){
       //Add Logic
       obj1.Obj2List.Add(obj2)  
    }
   else{
      // Update logic
   }
}

But obj2.Id is never null.Id is of type ObjectId. How can i check for logic to see if need to insert or update ? I am using asp.net MVC 3 and Mongo DB using the official C# drivers.

Thanks

  • 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-08T07:37:32+00:00Added an answer on June 8, 2026 at 7:37 am

    The ObjectId type is a struct, not a class – so it’s never going to be null. Check for ObjectId.Empty, instead.

    A word of caution, though: I suppose that you are storing the id of Object2 in some hidden field between requests. If that is the case, be aware that malicious user can easily change the ID by using an HTTP proxy (such as Fiddler), thus tricking you into believing that the Object2 is being updated instead of added.

    Depending on context of what you are trying to do, I would suggest performing some additional checks to more reliably determine if you should insert or update your object.

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

Sidebar

Related Questions

If I have an object public class Car { public List<UpdatePart> updatePartList {get; set;}
I have an ASP.NET WebService that returns an object of List public class Students
I have class A with a public std::list<int> object list_ . Class B ,
Let's say I have an object: public class CustomObj { DateTime Date { get;
I have the following object: public class QueueItem { public long _id { get;
I have a custom object ExportType : public class ExportType{ protected String name; protected
I have the following object: public class MyClass { public int Id { get;
I have the following object: public class Client { [BsonId] public string Name {
I have this object : public class MyObject { public int Id { get;
I have the object, which contain the list of objects. public class Product: IProduct

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.