开发者

Trying to use Uploadify in an MVC3 application what is the problem?

Why doesn't the file input element show up at all??? see code and screen shot below. I've spent the last few hours researching this on every forum I can find. I cannot get a consistent answer.

<!DOCTYPE html>
<html>
<head><title>

    Home Page

</title><link href="mvc3/Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="/mvc3/Scripts/jquery-1.5.1.js" type="text/javascript"></script>
    <script src="/mvc3/uploadify/jquery.uploadify.v2.1.4.js" type="text/javascript"></script>
    <script src="/mvc3/uploadify/swfobject.js" type="text/javascript"></script>
        <script type="text/javascript">
            jQuery.noConflict();
            jQuery(document).ready(function () {
                jQuery("#dr405").uploadify({
                    'uploader': 'uploadify.swf',
                    'cancelImg': 'cancel.png',
                    'buttonText': 'Browse Files',
                    'script': 'Uploader.ashx',
                    'folder': 'uploads',
                    'fileDesc': 'Image Files',
                    'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
                    'multi': true,
                    'auto': true
                });
            }); 
    </script> 
</head>
<body>
    <div class="page">
        <div id="header">
            <div id="title">
                <h1>My MVC Application</h1>
            </div>
            <div id="logindisplay">

        Welcome <strong>dougrchamberlain</strong>!
        [ <a href="/mvc3/Account/LogOff">Log Off</a> ]

            </div> 
            <div id="menucontainer">
                <ul id="menu">
                    <li><a href="/mvc3/">Home</a></li>
                    <li><a href="/mvc3/Home/About">About</a></li>
                </ul>
            </div>
        </div>
        <div id="main">

    <h2>Welcome to ASP.NET MVC!</h2>

    <p>Please upload your return</p&开发者_Python百科gt;   
    <input type="file" name="dr405" id="dr405" />


            <div id="footer">
            </div>
        </div>
    </div>
</body>
</html>

Trying to use Uploadify in an MVC3 application what is the problem?

Update

After fixing the url references. To actually point to the files in question, here is what I am seeing on my end.

Trying to use Uploadify in an MVC3 application what is the problem?


The url to the uploadify.swf looks wrong. I would recommend you always using URL helpers when dealing with urls:

jQuery("#dr405").uploadify({
    'uploader': '@Url.Content("~/mvc3/uploadify/uploadify.swf")',
    'cancelImg': 'cancel.png',
    ...
});


I had the same issue, although I was not using an ashx. The problem was that I wasn't referencing my controller's method correctly. My controller is named FileController.cs so instead of 'script': 'FileController/Upload', I used 'script':'File/Upload' and now no more IO Error - it calls the function in the controller correctly.

<script type="text/javascript">
$(document).ready(function () {
    $("#file_upload").uploadify({
        'uploader': '/uploadify/uploadify.swf',
        'script': '/File/Upload',
        'cancelImg': '/uploadify/cancel.png',
        'multi': true,
        'auto': true,
        'buttonText': 'SELECT',
        'onComplete': function (event, queueID, fileObj, response, data) {
            $("#" + $(this).attr('id') + queueID + " .percentage").text(' - Completed');
            return false;
         }
    });
});

public string Upload(HttpPostedFileBase fileData)
    {
        var fileName = this.Server.MapPath("~/uploads/" + System.IO.Path.GetFileName(fileData.FileName));
        fileData.SaveAs(fileName);
        return "ok";
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜