Database Contains images , when I try to edit the text , I need to upload images again , please suggest.
The problem is your design saves everything the user submits.
I would use standard MVC patterns (see any tutorial). First load the entity from the database using the Id submitted by the user. Next, overwrite the image arrays if the user uploaded a file. Finally save the entity not the model submitted by the user.
Below is an example of the pattern. I did not test the code so yo might have to tweak it a bit but it should be enough to understand the pattern.
public async Task<IActionResult> Edit(int id, [Bind("Sno,No,Topic,QuestionTitle,Opt1,Opt2,Opt3,Opt4,Answer,Time,Correct,Solution,Imagedata,Imagesol")] Questionsimg questionsimg, IFormFile imagedata, IFormFile imagesol)
{
var myEntity = _context.Questionsimg.FirstOrDefault(e => e.Sno = Id);
if (myEntity == null || id != myEntity.Sno)
{
return NotFound();
}
if (imagedata != null)
{
if (imagedata.Length > 0)
{
using (var target = new MemoryStream())
{
imagedata.CopyTo(target);
myEntity.Imagedata = target.ToArray();
}
}
}
if (imagesol != null)
{
if (imagesol.Length > 0)
{
using (var target = new MemoryStream())
{
imagesol.CopyTo(target);
myEntity.Imagesol = target.ToArray();
}
}
}
if (ModelState.IsValid)
{
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!QuestionsimgExists(questionsimg.Sno))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
return View(questionsimg);
}