osm*_*nes 7 asp.net upload kendo-ui
我想使用Kendo UI开发一个网站.我可以使用其他资格kendo-ui
.但是,我无法使用ASP.NET上传文件.是否有任何示例代码或文档可以解决此问题?
这是使它适合我的原因:
JS:
$(document).ready(function () {
$(".attachmentUpload").kendoUpload({
async: {
saveUrl: "SaveAttachment.aspx",
autoUpload: true
}
});
});
Run Code Online (Sandbox Code Playgroud)
页:
<input name="attachmentUpload" id="attachmentUpload" type="file" class="attachmentUpload" />
Run Code Online (Sandbox Code Playgroud)
SaveAttachment.aspx.cs
public partial class SaveAttachment : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1;
try
{
HttpPostedFile postedFile = Request.Files["attachmentUpload"];
//do something with your postedfile
Response.ContentType = "application/json";
Response.Write("{}");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
SaveAttachment.aspx:
<%@ Page Language="C#" CodeBehind="SaveAttachment.aspx.cs" Inherits="Nstar.WebUI.Pages.SaveAttachment" EnableTheming="false" StyleSheetTheme="" Theme="" %>
Run Code Online (Sandbox Code Playgroud)
它通过使用与您的方法类似的方法起作用。我创建了一个 upload.aspx 网络表单并通过以下方式调用它:
$("#userImage").kendoUpload({
async: {
saveUrl: "upload.aspx"
}
});
Run Code Online (Sandbox Code Playgroud)
我在 upload.aspx 的 aspx.cs 文件中有这段代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ProcessRequest();
}
public void ProcessRequest()
{
Response.Expires = -1;
try
{
var db = new mypicksDBDataContext();
HttpPostedFile postedFile = Request.Files["photos"];
string savepath = Server.MapPath("userFolders/images/");
string filename = postedFile.FileName;
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
postedFile.SaveAs(savepath + filename);
Response.Write("upload");
}
catch (Exception ex)
{
Response.Write (ex.ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud)
效果很好。它上传了文件,但出现了新问题。如何将结果返回给kendoui. 它上传但始终显示错误和重试按钮。在 Kendo-ui 的文档中,它说返回空字符串以成功上传。我尝试了 Response.Write(""); 但它不起作用。
归档时间: |
|
查看次数: |
7345 次 |
最近记录: |