Display Image preview on Edit time

Controller Code


 public async Task<IActionResult> EditBlog(string Id)

        {

            DropDownInitialize();

            _returnModel = await _blogDetailsServices.GetBlog(Id);

            if (_returnModel.IsSuccess)

            {

                string path = ((EduWeb.Data.Entity.tblblogdetails)_returnModel.Data).ImagePath; // this Line Represent path coming from database  

                int pos = path.LastIndexOf("\\") + 1;

                ViewBag.image = path.Substring(pos, path.Length - pos); // Adding  in View Bag

                return View(_returnModel.Data);

            }

            else

            {

                return RedirectToAction("BlogList", "Blog", new { area = "Admin" });

            }

        } 


View Code


  <div class="form-group">

                    <label for="exampleInputEmail1">Upload Logo</label>

                    <input type="file" name="file" id="file" />

                </div>

                <div class="form-group">

                    <img src="/Logo/@ViewBag.image" style="width:200px; height:200px" class="img" alt="Logo" /> 

-- Here logo is folder name

                </div>


Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls