0

I have a file input control:

<input type="file" id="fileUploadControl" />

On selecting an image file using this file control the selected image src has to be updated in img tag:

<img id="profileImage" width="80%" height="80%" />

I used the folowing jQuery code to update the src:

$("#fileUploadControl").on('change', function(){
     $("#profileImage ").attr('src', 'url(file://' + $(this).val() + ')');
})

The above code works in ordinary HTML page but when I use this code inside the MVC 4 .cshtml file it didn't work.

What is the reason and how do I overcome this problem?

4

1 回答 1

0

我已经在我的一个 asp.net 项目中做到了这一点,这对你有帮助吗

文件上传控件

<asp:FileUpload ID="screenUpload" runat="server" onchange="readURL(this);"/>

图像控制

<img width="100" id="imgProjImage" runat="server" src=""/>

功能

function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function(e) {
                    $('#imgProjImage').attr('src', e.target.result);
                }

                reader.readAsDataURL(input.files[0]);
            }
        }
于 2013-04-17T08:46:21.810 回答