首页 > 解决方案 > MVC 查看图像拖放功能

问题描述

我在 bootstrap 4 中有 mvc .net 核心项目,如您所见,图像功能运行良好,但是中心没有拖放功能,如果我尝试在“选择文件”上拖动图像,它可以工作但不能在中心所以你能帮我拖放功能吗?

我不希望代码上传,图像不应该上传到服务器端,还需要确保右侧有关闭按钮,该按钮应保持不变。

在此处输入图像描述

JavaScript

$('.img-wrap .close').on('click', function () {
  var id = $(this).closest('.img-wrap').find('imgInp').data('id');
  $('#imgInp').attr('src', '');
  $("#file").val('');
});

CSS

.imgdrop {
  height: 30px;
}

.img-wrap {
  position: relative;
  display: inline-block;
  border: 1px red solid;
  font-size: 0;
}

.img-wrap .close {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 100;
  background-color: #FFF;
  padding: 5px 2px 2px;
  color: #000;
  font-weight: bold;
  cursor: pointer;
  opacity: .2;
  text-align: center;
  font-size: 22px;
  line-height: 10px;
  border-radius: 50%;
}

.img-wrap:hover .close {
  opacity: 1;
}

HTML

@Html.Label("Image"@*, new { @class = "control-label col-md-2"}*@)
<div class="col-md-3">
  <input type="file" id="file" name="file" class=" imgdrop" multiple="multiple" />
  <div class="img-wrap">
    <span class="close">&times;</span>
    <img src="#" alt="Alternate Image" id="imgInp" width="200" height="200" />
  </div>
</div>

标签: asp.net-mvchtmlasp.net-corebootstrap-4

解决方案


推荐阅读