'how can i show the data that the user entered in the file input when he want to edit it

for your information the file is saved as a binary data

here is is the model:

public class Movie
{
    [Key]
    public int MovieId { get; set; }
    public string MovieName { get; set; }
    public string MovieDescription { get; set; }
    public byte[] MovieImage { get; set; }
    public string MovieTrailer { get; set; }

    //FK
    public int AdminId { get; set; }

    //Navigation
    public Admin Admin { get; set; }
    public ICollection<Event> Events { get; set; }
    public AddingCategory AddingCategory { get; set; }
    public ViewingMovie ViewingMovie { get; set; }
}

}

And here is the controller :

public async Task<IActionResult> Edit(int? id)
    {
        if (id == null)
        {
            return NotFound();
        }

        var movie = await _context.tblMovies.FindAsync(id);
        if (movie == null)
        {
            return NotFound();
        }
        ViewData["AdminId"] = new SelectList(_context.Set<Admin>(), "AdminId", "Email", selectedValue: movie.AdminId);
        return View(movie);
    }

    // POST: Movies/Edit/5
    // To protect from overposting attacks, enable the specific properties you want to bind to.
    // For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<IActionResult> Edit(int id, [Bind("MovieId,MovieName,MovieDescription,MovieImage,MovieTrailer,AdminId")] Movie movie, IFormFile MovieImage)
    {
        if (id != movie.MovieId)
        {
            return NotFound();
        }

        if (MovieImage != null)
        {
            //This code is used to copy image to DataBase
            using (var myStream = new MemoryStream())
            {
                await MovieImage.CopyToAsync(myStream);
                movie.MovieImage = myStream.ToArray();
            }
        }

        if (ModelState.IsValid)
        {
            try
            {
                _context.Update(movie);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieExists(movie.MovieId))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }
            return RedirectToAction(nameof(Index));
        }
        ViewData["AdminId"] = new SelectList(_context.Set<Admin>(), "AdminId", "Email", movie.AdminId);
        return View(movie);
    }

and the last here is the edit view:

<div class="row">
<div class="col-md-4">
    <form asp-action="Edit" method="post" enctype="multipart/form-data">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <input type="hidden" asp-for="MovieId" />
        <div class="form-group">
            <label asp-for="MovieName" class="control-label"></label>
            <input asp-for="MovieName" class="form-control" />
            <span asp-validation-for="MovieName" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="MovieDescription" class="control-label"></label>
            <input asp-for="MovieDescription" class="form-control" />
            <span asp-validation-for="MovieDescription" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="MovieImage" class="control-label"></label>
            <input asp-for="MovieImage" class="form-control" type="file" />
            <span asp-validation-for="MovieImage" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="MovieTrailer" class="control-label"></label>
            <input asp-for="MovieTrailer" class="form-control" />
            <span asp-validation-for="MovieTrailer" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="AdminId" class="control-label"></label>
            <select asp-for="AdminId" class="form-control" asp-items="ViewBag.AdminId"></select>
            <span asp-validation-for="AdminId" class="text-danger"></span>
        </div>
        <div class="form-group">
            <input type="submit" value="Save" class="btn btn-primary" />
        </div>
    </form>
</div>

all i want is to show what the user entered in the file input and if he want to edit it or keep as it is. i have been struggling with this problem in days PLEASE somebody help me out



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source