简体   繁体   English

显示已上传图片的缩略图-MVC4

[英]Show Thumbnail of uploaded pic - MVC4

I am working on an application in MVC4 C# 我正在使用MVC4 C#中的应用程序

I have a Details page where a button "Upload Photo" is present. 我有一个“详细信息”页面,其中显示“上传照片”按钮。 On click of the button , a pop up page opens (via Jquery) where I can upload&crop pics. 单击该按钮后,将打开一个弹出页面(通过Jquery),我可以在其中上传和裁剪照片。 Once cropped , I need to click "Confirm Pic" button present in the pop-up page. 裁剪后,我需要点击弹出页面中的“确认图片”按钮。 On click of "Confirm Pic", this pop up should get closed and the thumbnail of the cropped pic needs to be displayed on the parent page ie Details screen. 单击“确认图片”后,该弹出窗口将被关闭,裁剪后的图片的缩略图需要显示在父页面(即“详细信息”屏幕)上。

Issue: When I click "Confirm Pic" button, form post occurs on the parent page, due to which parent page is also getting refreshed , as a result I am losing all th unsaved data on the parent page 问题:当我单击“确认图片”按钮时,父页面上也会发生表单发布,由于该父页面也正在刷新,结果我丢失了父页面上所有未保存的数据

Currently I am out of ideas :( :( Any ideas are appreciated.. 目前我没有想法:( :(任何想法都值得赞赏。

On click of the button, instead of opening a popup page, you should display the form in a modal . 单击该按钮时,您应该以模式形式显示表单,而不是打开弹出页面。 Then when you upload your cropped image, you should do it using ajax. 然后,当您上传裁剪的图像时,应该使用ajax进行处理。

EDIT 编辑

 $("#form").on("submit", function(e) { e.preventDefault(); $.ajax({ url: 'urlHere', type: 'POST', data: new FormData(this), processData: false, contentType: false }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form id="form"> <input type="file" name="myFile"> <input type="submit"> </form> 

You should know that it will not work in IE before version 10. 您应该知道它在版本10之前的IE中不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM