zeeshan akram

zeeshan akram

  • 1.4k
  • 325
  • 18.2k

Selected value is not fill in Dropdown list c# mvc

Apr 4 2020 4:17 AM
Hi, I want to edit my product so I have a three dropdown when I click Edit Button product load and Run this function Edit Product data load in result variable but not shown on the front end.  I have shared the result of data in the image. a kindly expert can you tell me where I am wrong.
 
 
Model
  1.    public class ProductViewModel  
  2.     {  
  3.   
  4.        public Product listProducts = new Product();  
  5.         public List listProductDetails = new List();  
  6. }  
 Function c# 
  1. public ActionResult EditProduct(int id)  
  2.         {  
  3.             List PTlist = _IproductType.PTList();  
  4.             ViewBag.Ptlist = new SelectList(PTlist, "PType_ID""P_Name");  
  5.   
  6.             //Product Color List  
  7.             List pColorList = _IProductColor.PColorlist();  
  8.             ViewBag.pColor_List = new SelectList(pColorList, "C_ID""C_Name_OR_Code");  
  9.   
  10.             List pSizeList = _ISize.pSizeList();  
  11.             ViewBag.pSizeLists = new SelectList(pSizeList, "S_ID""S_Size");  
  12.   
  13.             var result = _IProducts.GetProductByID(id);  
  14.   
  15.             return View(result);  
  16.         }  
 Result  
 
view
  1. <div class="form-group">    
  2.                                     <label class="control-label col-lg-3"><span data-toggle="tooltip" class="label-tooltip" data-original-title="Product type"> Product Category </span></label>    
  3.                                     <div class="col-lg-9">    
  4.                                         <div class="col-sm-9 controls">    
  5.                                             @if (ViewBag.Ptlist != null)    
  6.                                             {    
  7.                                                 @Html.DropDownListFor(m => m.listProducts.PType_ID, ViewBag.Ptlist as SelectList, "Choose Product Category", new { @class = "", @id = "PTypeID" })    
  8.                                             }    
  9.                                         </div>    
  10.   
  11.                                     </div>    
  12.                                 </div>    
  13.                                 <div class="form-group">    
  14.                                     <label class="control-label col-lg-3"><span data-toggle="tooltip" class="label-tooltip" data-original-title="Product type"> Product Color </span></label>    
  15.                                     <div class="col-lg-9">    
  16.                                         <div class="col-sm-9 controls">    
  17.                                             @if (ViewBag.pColor_List != null)    
  18.                                             {    
  19.                                                 @Html.DropDownListFor(m => m.listProducts.P_Color_ID, ViewBag.pColor_List as SelectList, "Choose Product Color", new { @class = "", @id = "PColorID" })    
  20.                                             }    
  21.                                         </div>    
  22.   
  23.                                     </div>    
  24.                                 </div>    
  25.                                 <div class="form-group">    
  26.                                     <label class="control-label col-lg-3"><span data-toggle="tooltip" class="label-tooltip" data-original-title="Product type"> Product Size </span></label>    
  27.                                     <div class="col-lg-9">    
  28.                                         <div class="col-sm-9 controls">    
  29.                                             @if (ViewBag.pSizeLists != null)    
  30.                                             {    
  31.                                                 @Html.DropDownListFor(m => m.listProducts.P_SizeID, ViewBag.pSizeLists as SelectList, "Choose Product Size", new { @class = "", @id = "PSizeID" })    
  32.                                             }    
  33.                                         </div>    
  34.   
  35.                                     </div>    
  36.                                 </div>    
 
  

Answers (2)