c# - Linq Non-static Methord Requires A Target -


Not sure why, but this line is causing me problems:

  public zero AddToCart (Product Products) {var cartItem = storeDB.Carts.SingleOrDefault ((c.productID) == product.ProductID); }   

I'm telling this to a controller.

  Public Functional AddToCart (int productID) {var added product = store DB.products.fund (Product ID); Var cart = ShoppingCart.GetCart (this.HttpContent); Cart.AddToCart (addedProduct); Return Redirect Action ("Index"); }   

I am feeling that your first query, storeDB.Products < / Code>, returning a zero value (because the entity you are trying to find did not get it). After this, added product is zero, and you try to refer to it in other LINQ statements, which throws a null reference exception.

Obviously, a null reference exception is being used with your storeDB reference in the inside expression, "A goal is required for the method" exception Appears in appearance.

null before using it in the AddToCart method and using it in that LINQ statement.

  Public Functional AddToCart (int productID) {var added product = storeDB.Products.Find (Product ID); If (added product == zero) {// bring some reasonable action here / or possibly throws an exception (can not add missing product to cart)} cart = shopping cart. Gettart (this .htp content); Cart.AddToCart (addedProduct); Return Redirect Action ("Index"); }   

In addition, your code will not compile after your first edit. You have c = & gt; needs to be returned.

  var cartItem = storeDB.Carts.SingleOrDefault (c => c.productID == product.ProductID);    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -