88487901 2010-11-04
代码如下:
<asp:Content ID="Content3" ContentPlaceHolderID="Head" runat="server"> <script src="<%=Url.Content("~/Scripts/jquery-1.4.1.js") %>" type="text/javascript"></script> <script src="<%=Url.Content("~/Scripts/jquery.form.js") %>" type="text/javascript"></script> <script type="text/javascript"> $(function () { //上传图片 $("#btnUpload").click(function () { if ($("#flUpload").val() == "") { alert("请选择一个图片文件,再点击上传。"); return; } $('#UpLoadForm').ajaxSubmit({ success: function (html, status) { var result = html.replace("<pre>", ""); result = result.replace("</pre>", ""); $("#image").attr('src', result); alert(result); } }); }); });
代码如下:
namespace TestMvc.Utility { /// <summary> /// Summary description for PicUploadHander /// </summary> public class PicUploadHander : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //验证上传的权限TODO string _fileNamePath = ""; try { _fileNamePath = context.Request.Files[0].FileName; //开始上传 string _savedFileResult = UpLoadImage(_fileNamePath, context); context.Response.Write(_savedFileResult); } catch { context.Response.Write("上传提交出错"); } }