Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
I have a partial view where in user can upload a file. following is my code

Partial View:
@model UploadeRateModel
@Html.ValidationSummary(true)

<iframe id="uploadTrg" name="uploadTrg" height="0" width="0" frameborder="0" scrolling="yes" style="display:none;"></iframe>

@using (Html.BeginForm("UploadExchangeRate", "ExchangeRates", FormMethod.Post, new { @id = "UploadRateForm", @enctype = "multipart/form-data", @target = "uploadTrg" }))
{
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
    <script>
        $(document).ready(function () {
            $('input[id=lefile]').change(function () {
                $('#photoCover').val($(this).val());
            });
        });
    </script>

<div id="UploadSheet_Div" style="margin-removed20px;margin-removed8px;">
            <div class="input-group" style="width:100%;">
                @Html.LabelFor(m => m.File, "Upload Rate Sheet- using Supply Rate File Name*", new { @style = "color: #002663;width:216px;display:inline-block;" })
                <span class="input-group" style="display:inline-block;">
                    @Html.TextBoxFor(m => m.File, new { @id = "lefile", @type = "file", @style = "display:none;" })

                    @Html.TextBox("File", null, new { @id = "photoCover", @class = "input-large", @type = "text", @style = "border-radius:5px;margin-left:60px;vertical-align:top;" })
                    <a class="btn" >Browse</a>


                    @Html.ValidationMessageFor(m => m.File)
                </span>
            </div>
        </div>

<div style="margin-removed21px;margin-removed20px;">
            <button id="btnUpload" type="submit" style="color: white; display: inline-block;background: #00693C;border: antiquewhite;border-radius: 3px;margin-left: 235px;padding: 8px;margin-right: 1px;">Upload</button>
        </div>


Javascript Code:
$(document).on("submit", "#UploadRateForm", function () {
            $('#btnUpload').attr('disabled', 'disabled');
            $("#uploadTrg").unbind('load');
            $("#uploadTrg").load(function () {

                var stringContent = $(this).contents().find("pre").html();

                var objJson = jQuery.parseJSON(stringContent);

                var SplittedValue = objJson.split(",");
                if (SplittedValue != null) {
                    if (SplittedValue[0] == "true" || SplittedValue[0] == "True") {
                        ExRateSheetableLoad(SplittedValue[1], "P");
                        $('#SupplyDescText').val(SplittedValue[2])
                        $("#UploadSheetShowDiv").slideDown("slow");
                        $("#UploadSuccessMsg_Div").slideDown("slow");
                    }
                    else if (SplittedValue[0] == "false" || SplittedValue[0] == "False") {
                        $('#UploadErrorDiv').show();
                        $('#lblUpload_Errormsg').text(SplittedValue[1]);
                    }
                }
                $('#btnUpload').removeAttr('disabled', 'disabled');
            });

        });
        $(document).on('click', "#btnUpload", function () {
            var form = $('#UploadRateForm');
            $("#RatesheetTable_Div").html('');
            $("#UploadSuccessMsg_Div").hide();
            $("#btnUpload").addClass("disabled");
            $('#UploadErrorDiv').slideUp();
            form.submit();
            return false;

        });


When I try to submit the form using JavaScript, it gives me Access Denied error for IE. It works fine for rest browser.

Can anyone tell me is there is security issue when it comes to file uploading in IE?
What can be the solution for the issue?

Thanks in advance
Posted
Updated 5-Jan-15 20:55pm
v2
Comments
Kornfeld Eliyahu Peter 6-Jan-15 2:14am    
Can you tell us where (on which line) the error is?
dhage.prashant01 6-Jan-15 2:23am    
When I tried to debug the code, it is where from following line in submit action
$('#btnUpload').attr('disabled', 'disabled');

It goes at following code in jQuery file and gives error

jQuery.event.triggered = type;
try {
elem[ type ]();
} catch ( e ) {
// IE<9 dies on focus/blur to hidden element (#1486,#12518)
// only reproducible on winXP IE8 native, not IE9 in IE8 mode
}
dhage.prashant01 6-Jan-15 2:58am    
TQ Kornfeld Eliyahu Peter, I got the solution :)

1 solution

IE does not allow following:
1. You cannot read the "value" of the element as it holds the filename.
2. You can't fire up the file selection menu via JS.
3. You can't fire submit of the file uploader control via JS.

I was trying to do 2 point in following code
Browse

I just put the hyperlink inside the label as below:
XML
<label for="lefile">
   <a class="btn" style="color: #002663;text-decoration:underline;font- family:Arial;font-size:13px;vertical-align:top">Browse</a>
</label>


It worked for me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900