views:

28

answers:

0

Hello All,

I am having a page view products and in that grid I am having a Edit link whick takes me to the edit page and now On the Edit I am having a file upload control. How will I use the request.files because while editing something We use collections in the controller class please tell me how will I do this, It is very necessary.

My controller is this

public ActionResult EditProduct(int prod_id, tbl_PRODUCTS collection)
    {
        try
        {

            AdminImplementation _adminImplementation = new AdminImplementation();
            int i = _adminImplementation.updateProduct (prod_id, collection);
            ViewData["succm"] = "category updated successfully";


            IList<tbl_PRODUCT_CATEGORY> CategorybyId = _adminImplementation.fetchCategoryById(category_id);



            return View(CategorybyId.First());


        }
        catch
        {
            return View();
        }
    }

tbl_PRODUCTS collection my problem is with this.In the add product I have done like this and it is working absolutely fine

public ActionResult AddProduct(string Categories, string product_name, string product_price, string product_desc, string weight, string image_name, string img_content, string available_qty, string isFeature)
    {

        foreach (string inputTagName in Request.Files)
        {
            HttpPostedFileBase file = Request.Files[inputTagName];
            if (file.ContentLength > 0)
            {
                string filePath = Path.Combine(HttpContext.Server.MapPath("../Content/Uploads"), Path.GetFileName(file.FileName));
                string filecontent = Path.Combine(HttpContext.Server.MapPath("../Content/Uploads"), Path.GetFileName(file.ContentType));

                image_name = Path.GetFileName(file.FileName);
                img_content = Path.GetFileName(file.ContentType);

                file.SaveAs(filePath);

            }
        }


        AdminImplementation _adminImplementation = new AdminImplementation();

        Boolean   isfeature = Convert .ToBoolean(isFeature);

        if (isfeature)
        {
            isFeature = "Featured";
        }
        else
        {
            isFeature = "NotFeatured";
        }


        int i = _adminImplementation.addproduct(Categories, product_name, product_price, product_desc, weight, image_name, img_content, available_qty, isFeature);

        ViewData["succm"] = "Product added successfully";
        return View ();

    }

Thanks Ritz