-1

I am using this code with the help of one tutorial, but still i am unable to upload the image, i mean the image is not appearing, please someone help me on this

This is the code I have used:-

<div class="col-md-6">
    <div class="form-group">
        @Html.LabelFor(model => model.ImgPath, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            <img src="@Url.Content(Model.ImgPath)" style="margin:10px" height="200" width="200" id="imagePreview" />
            <input type="file" name="ImageUpload" accept="image/jpeg, image/png" onchange="ShowImagePreview(this, document.getElementById('imagePreview')" />
        </div>
    </div>
</div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

-1

If your image is not uploading, i think you should check you form tag and make it something like this

<form method="post" enctype="multipart/form-data">
//your image upload
<input type="file" name="ImageUpload" accept="image/jpeg, image/png" />
</form>

then you can use the Request.Files and access all the files sent or if you want it strongly embedded use

//this for Asp.Net Core
public IActionResult(IFormFile ImageUpload)
{
   //Everything here
}

//Or this for Asp.Net
public ActionResult(HttpPostedFileBase ImageUpload)
{
   //Everything else here
}

Read this stackoverflow post to understand about it

Formula12
  • 305
  • 1
  • 3
  • 14