這篇文章給大家介紹如何在asp.net中利用jQuery Uploadify實現一個附件上傳功能,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
Uploadify是JQuery的一個上傳插件,實現的效果非常不錯,帶進度顯示。Uploadify官方網址:http://www.uploadify.com/,在MVC中使用的方法可以參考 jQuery Uploadify在ASP.NET MVC3中的使用 和 Asp.net Mvc中使用uploadify實現圖片縮放保存。
本文是一個簡單的介紹Demo,主要是動態傳遞參數方法:通過formdata 向處理程序傳遞額外的表單數據:
$(function () {
var taskId = "<%= TaskID %>";
var activityId = "<%= ActivityId %>";
var userId = "<%= GetCurrentLoginUser().ID %>";
$("#<%=FileUpload1.ClientID %>").uploadify(
{
'swf': 'uploadify/uploadify.swf',
'uploader': 'UploadHandler.aspx',
'auto': false,
'method': 'post',
'multi': true,
'buttonText': '瀏覽',
'buttonImg': 'uploadify/browse.jpg',
'folder': '../uploadfile',
'fileDesc': '附件',
'onUploadStart': function (event, data) { //this is where you will send the form //data, but remember to get if from post in the .ashx file, by contex.Request["gallaryId"]
$("#<%=FileUpload1.ClientID %>").uploadify('settings', 'formData',
{ 'taskId': taskId, 'activityId': activityId, 'userId': userId, 'secInfo': $("#<%=ddlsecInfo.ClientID %>").val()} //note hiddenGallaryId would //have the gallaryId which im sending through post , make sure it is rendered in your page( //i.e.not concealed by a multiview control e.t.c)
);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:DropDownList ID="ddlsecInfo" runat="server">
<asp:ListItem Text="公開" Value="1"> </asp:ListItem>
<asp:ListItem Text="普通" Value="2"> </asp:ListItem>
<asp:ListItem Text="機密" Value="3"> </asp:ListItem>
</asp:DropDownList>
<a href="javascript: $('#<%=FileUpload1.ClientID %>').uploadify('upload','*')">上傳</a>
<a href="javascript:$('#<%=FileUpload1.ClientID %>').uploadify('cancel','*')">取消上傳</a>
</form>
</body>
</html>
關于如何在asp.net中利用jQuery Uploadify實現一個附件上傳功能就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。