Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET ListControl MVC3 Model , +
Hi,
 
I am trying to assign a value to a model of specific index inside a list of models. However it assigns to all elements irrespective of index. tried even removeat and insert too, nothing seem to work. code snippet as below.
 
BasketDetailsModel basketDetailsModel = SessionManager.Get<BasketDetailsModel>(SessionConstants.BrowseOrderModels);
                    //BasketPersonalisedItemModel basketPersonalisedItemModel = basketDetailsModel.basketPersonalisedItemModel[personalisedItemIndex - 1];
                    BasketPersonalisedItemModel basketPersonalisedItemModel = new BasketPersonalisedItemModel();
                    basketPersonalisedItemModel = basketDetailsModel.basketPersonalisedItemModel[personalisedItemIndex - 1];
                    if (basketDetailsModel.basketPersonalisedItemModel.Count > 0)
                    {
                        List<AttributeValueModel> attributeValueModels = new List<AttributeValueModel>();
                        ProductAttributeModel productAttributeModel = new ProductAttributeModel();
                        short attributeId = 0;
                        string attributeValue = null;
                        string attributeName = null;
                        for (int basketItemIndex = 1; basketItemIndex <= Convert.ToInt16(Request.Form["PersonalisedAttributeCount"]); basketItemIndex++)
                        {
                            AttributeValueModel orderItemAttributeModel = new AttributeValueModel();
                            attributeId = Convert.ToInt16(Request.Form["AttributeId" + basketItemIndex.ToString()].ToString());
                            attributeName = Request.Form["AttributeName" + basketItemIndex.ToString()].ToString();
                            attributeValue = Request.Form["AttributeValue" + basketItemIndex.ToString()].ToString();
                            orderItemAttributeModel.AttributeId = attributeId;
                            orderItemAttributeModel.AttributeValue = attributeValue;
                            orderItemAttributeModel.AttributeName = attributeName;
                            attributeValueModels.Add(orderItemAttributeModel);
                        }
                        productAttributeModel.AttributeValueModels = attributeValueModels;
                        productAttributeModel.ProductId = Convert.ToInt32(Request.Form["ProductId"]);
                        productAttributeModel.ProductCode = Request.Form["ProductCode"];
                        basketPersonalisedItemModel.ProductAttributeModel = productAttributeModel;
                        //basketDetailsModel.basketPersonalisedItemModel[personalisedItemIndex - 1].ProductAttributeModel = productAttributeModel;
                        basketDetailsModel.basketPersonalisedItemModel.RemoveAt(personalisedItemIndex - 1);
                        basketDetailsModel.basketPersonalisedItemModel.Insert(personalisedItemIndex - 1, basketPersonalisedItemModel);
                        Session[SessionConstants.BrowseOrderModels] = basketDetailsModel;
Posted 1-Jul-12 16:45pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 385
1 DamithSL 210
2 Kornfeld Eliyahu Peter 210
3 OriginalGriff 180
4 Peter Leow 95
0 OriginalGriff 7,215
1 DamithSL 5,199
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,757
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 1 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100