Welcome Guest, Not a member yet? Register   Sign In
Dropdown Selected value not shown on edit from
#1

(This post was last modified: 10-28-2021, 11:57 PM by Dina_Az.)

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 done omegleazar from my side everything is correct but I don't know why the value is not shown in my dropdown during the edit.

Any Expert can see the code and kindly tell me where I am wrong and how to correct this issue.

Models

public class ProductViewModel { public Product listProducts = new Product(); public List<ProductDetail> listProductDetails = new List<ProductDetail>(); } Product

public class Product { public int P_SizeID { get; set; } public int P_Color_ID { get; set; } public int PType_ID { get; set; } } Product Details

public class ProductDetails { Public Int64 ProductID { get; set; } public string PDescription { get; set; } public string Model { get; set; } public string chatrandom Condition { get; set; } public string OS { get; set; } public string DualSim { get; set; } public string TouchScreen { get; set; } public string ScreenSize { get; set; } } Function c#

public ActionResult EditProduct(int id) { List<ProductType> PTlist = _IproductType.PTList(); ViewBag.Ptlist = new SelectList(PTlist, "PType_ID", "P_Name");

//Product Color List 
List<P_Color> pColorList = _IProductColor.PColorlist();
ViewBag.pColor_List = new SelectList(pColorList, "C_ID", "C_Name_OR_Code");

List<P_Size> pSizeList = _ISize.pSizeList();
ViewBag.pSizeLists = new SelectList(pSizeList, "S_ID", "S_Size");

var result = _IProducts.GetProductByID(id);

return View(result);

} C# Function

public ProductViewModel GetProductByID(int ID) { ProductViewModel listprod = new ProductViewModel();

try
{
    var productsl = (from p in _db.Products
                    where p.ProductID == ID
                    select p).FirstOrDefault();


    var productD = (from pd in _db.ProductDetails
                    join b in _db.Products on pd.ProductID equals b.ProductID
                    where pd.ProductID == ID
                    select pd).ToList();
    return new ProductViewModel { listProducts = productsl, listProductDetails = productD };
}

catch (Exception)
{

    throw;
}
} View

<div class="form-group"> <label class="control-label col-lg-3"> <span data-toggle="tooltip" class="label-tooltip" data-original-title="Product type"> Product Category </span> </label> <div class="col-lg-9"> <div class="col-sm-9 controls"> @if (ViewBag.Ptlist != null) { @Html.DropDownListFor(m => m.listProducts.PType_ID, ViewBag.Ptlist as SelectList, "Choose Product Category", new { @class = "", @id = "PTypeID" }) } </div>

</div>
</div> <div class="form-group"> <label class="control-label col-lg-3"><span data-toggle="tooltip" class="label-tooltip" data-original-title="Product type"> Product Color </span></label> <div class="col-lg-9"> <div class="col-sm-9 controls"> @if (ViewBag.pColor_List != null) { @Html.DropDownListFor(m => m.listProducts.P_Color_ID, ViewBag.pColor_List as SelectList, "Choose Product Color", new { @class = "", @id = "PColorID" }) } </div>

</div>
</div> <div class="form-group"> <label class="control-label col-lg-3"><span data-toggle="tooltip" class="label-tooltip" data-original-title="Product type"> Product Size </span></label> </div>
Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB