//后台代码
[HttpPost]
public ActionResult CreateCategory(HttpPostedFileBase file)
{
string url = Upload(file);
if(url== "empty")
{
return Json("{state:fault}");
}
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
var proxy = factory.CreateChannel();
//用户组请求类
ServicePostRequest<Guoany_Ga_B2BGCategory_InsertOrUpdate_Request> request = new ServicePostRequest<Guoany_Ga_B2BGCategory_InsertOrUpdate_Request>();
request.ExtraData = new Guoany_Ga_B2BGCategory_InsertOrUpdate_Request();
request.ExtraData.Parent_Id = "";
request.ExtraData.Creater = "";
request.ExtraData.Creattime = DateTime.Now;
request.ExtraData.Des = "";
request.ExtraData.Category_Id = Guid.NewGuid().ToString();
request.ExtraData.Category_Name = "";
request.ExtraData.Category_Url = url;
request.ExtraData.Is_del = false;
request.ExtraData.Is_show = true;
request.ExtraData.Is_Special = false;
request.ExtraData.Sort_No = 1;
ServicePostResponse<Guoany_Ga_B2BGCategory_InsertOrUpdate_Response> response = proxy.InsertOrUpdateB2B_G_Category(request);
// ViewData["Group_Response"] = response.Data;
bool result = response.Success; return Json("{state:success}");
}
public string Upload(HttpPostedFileBase file)
{
if (file == null)
{
return "empty";
}
var fileName = Path.Combine(Request.MapPath("~/Upload"), Path.GetFileName(file.FileName)); if (Directory.Exists(Server.MapPath("~/Upload")) == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(Server.MapPath("~/Upload"));
}
file.SaveAs(fileName);
return "upload/"+Path.GetFileName(file.FileName);
}
//-----------------------------------------------------------------------------------------
//前台代码 @{
ViewBag.Title = "类别列表";
} <script type="text/javascript">
$(function () {
var pager = $('#dg').datagrid().datagrid('getPager'); // get the pager of datagrid
pager.pagination({
buttons: [{
iconCls: 'icon-search',
handler: function () {
$('#dg').datagrid("reload");
}
}, {
iconCls: 'icon-add',
handler: function () {
alert('add');
}
}, {
iconCls: 'icon-edit',
handler: function () {
alert('edit');
},
iconCls: 'icon-remove',
handler: function () {
alert('删除');
}
}]
}); })
function searchCategory() {
var stopOrenable = $('#stopOrenable').combobox('getValue');
var txtCategoryName = $("#txtCategoryName").val();
var showOrNot = $("#showOrNot").is(":checked") == true ? 1 : 0;
var specilCategory = $("#specilCategory").is(":checked") == true ? 1 : 0; $('#dg').datagrid('load', {
queryParams: {
stopOrenable: stopOrenable,
txtCategoryName: txtCategoryName,
showOrNot: showOrNot,
specilCategory: specilCategory } });
//var randnum = Math.floor(Math.random() * 1000000);
//alert(randnum)
//var urls = '/Category_Manage/GetCategoryJsonList?randnum=' + randnum; }
function addCategory() {
$('#dd').dialog('open'); } function editCategory() { } function showCategory() { } function hidenCategory() { } function enabledCategory() { } function stopCategory() { }
</script> <script type="text/javascript">
function PreviewImage(imgFile) {
var filextension = imgFile.value.substring(imgFile.value.lastIndexOf("."), imgFile.value.length);
filextension = filextension.toLowerCase();
if ((filextension != '.jpg') && (filextension != '.gif') && (filextension != '.jpeg') && (filextension != '.png') && (filextension != '.bmp')) {
alert("对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢 !");
imgFile.focus();
}
else {
var path;
if (document.all)//IE
{
imgFile.select();
path = document.selection.createRange().text; document.getElementById("imgPreview").innerHTML = "";
document.getElementById("imgPreview").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\"" + path + "\")";//使用滤镜效果
}
else//FF
{
path = window.URL.createObjectURL(imgFile.files[0]);
var i = 0;
i++;
$("#imgPreview").append("<img id='img" + i + "' width='120px' height='100px' src='" + path + "'/>"); }
}
}
function submitContent()
{
var formData = new FormData();
var file = document.getElementById("upload").files[0];
formData.append("file", file);
$.ajax({
type: "POST",
url: '@Url.Action("CreateCategory", "Category_Manage")',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
alert("sucess");
},
error: function (error) {
alert("fault");
}
});
} </script>
<table id="dg" class="easyui-datagrid" title="商品类别列表" style="width:100%;height:250px"
data-options="rownumbers:true,singleSelect:true,url:'/Category_Manage/GetCategoryJsonList',method:'get',toolbar:'#tb',footer:'#ft',pagination:true">
<thead>
<tr>
<th data-options="field:'ParentCategoryName',width:80">上级类目</th>
<th data-options="field:'Category_Name',width:100">类目名称</th>
<th data-options="field:'Is_Del',width:80,align:'right'">启用状态</th>
<th data-options="field:'Des',width:80,align:'right'">描述</th>
<th data-options="field:'Is_Special',width:240">是否特殊项目</th>
<th data-options="field:'Is_show',width:60,align:'center'">展示状态</th>
<th data-options="field:'Sort_No',width:60,align:'center'">排序</th> </tr>
</thead>
</table>
<div id="tb" style="padding:2px 5px;">
<div>
<input type="button" value="新增" onclick="addCategory()" />
<input type="button" value="编辑" onclick="editCategory()" />
<input type="button" value="展示" onclick="showCategory()" />
<input type="button" value="隐藏" onclick="hidenCategory()" />
<input type="button" value="启用" onclick="enabledCategory()" />
<input type="button" value="停用" onclick="stopCategory()" />
</div>
类目名称 <input id="txtCategoryName" style="width:110px">
是否停用
<select id="stopOrenable" class="easyui-combobox" panelHeight="auto" style="width:100px">
<option value="1">是</option>
<option value="0">否</option>
</select>
<input type="checkbox" id="specilCategory" /> 特殊类目 <input type="checkbox" id="showOrNot" /> 是否展示
<a href="#" id="search" class="easyui-linkbutton" onclick="searchCategory()" iconCls="icon-search">搜索</a>
</div>
<div id="dd" class="easyui-dialog" title="新增/编辑"
data-options="iconCls:'icon-save',closed:true,modal: true,cache: false" style="width:800px;height:600px;padding:10px">
@using (Html.BeginForm("CreateCategory", "Category_Manage", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<table style="border:1px solid ;width:700px;height:500px;">
<tr>
<td>父类目:<input type="text" /></td>
<td colspan="2">
图片上传:<input type="file" name="file" style="width: 200px; height: 20px;" onchange="PreviewImage(this)" id="upload" />
<div id="imgPreview" style="width:120px; height:100px;margin-left: 280px;"></div> </td> </tr>
<tr><td>类目:<input type="text" /></tr>
<tr><td>是否特殊类目:<input type="checkbox" /></td><td>是否显示:<input type="checkbox" /></td></tr>
<tr><td rowspan="1">类描述<textarea rows="2"></textarea></td></tr>
<tr><td rowspan="1"><input onclick="submitContent()" value="提交" /></td></tr>
</table> }
</div>

  

asp.net mvc ajax FileUpload的更多相关文章

  1. ASP.NET MVC Ajax.ActionLink 简单用法

    ASP.NET MVC 项目中,如何使用类似于 iframe 的效果呢?或者说 Ajax 局部刷新,比如下面操作: 我们想要的效果是,点击 About 链接,页面不刷新(地址栏不变),然后下面的内容进 ...

  2. Asp.Net MVC ajax调用 .net 类库问题

    如果你还在为 ajax 调用 .net 类库还束手无策的话,相信这篇博客将帮助你解决这个世纪问题! 因为Visual Studio 内置了asp.net mvc ,不过当你添加asp.net mvc项 ...

  3. Asp.Net MVC Ajax

    将ASP.NET MVC中的form提交改为ajax提交 在ASP.NET MVC视图中通过 @using (Html.BeginForm()) 产生的是form表单提交代码,可以用javascrip ...

  4. ASP.NET MVC Ajax 伪造请求

    1.前言 CSRF(Cross-site request forgery)跨站请求伪造,ASP.NET MVC 应用通过使用AJAX请求来提升用户体验,浏览器开发者工具可以一览众山小,就很容易伪造了请 ...

  5. ASP.NET MVC ajax处理 AjaxResult

    1.统一ASPNET MVC 对ajax请求响应格式定义,方便前端统一处理ajax结果. 1)定义程序返回结果数据格式 /// <summary> /// 执行结果 /// </su ...

  6. ASP.NET MVC AJAX 请求中加入 antiforgerytoken 解决“所需的防伪表单字段“__RequestVerificationToken”不存在”问题

    在ASP.NET mvc中如果在表中使用了@Html.AntiForgeryToken(),ajax post不会请求成功 解决方法是在ajax中加入__RequestVerificationToke ...

  7. ASP.NET MVC AJAX的调用示例

    @{ ViewBag.Title = "Home Page"; //下面引用Jquery和unobtrusive-ajax } @Scripts.Render("~/bu ...

  8. asp.net mvc ajax 异步刷新例子

    这几天在asp.net中使用ajax来做异步刷新,这里整理一下 1.首先看前台页面点击的时候调用函数 function shuxin() { $.ajax( { url: "GetValue ...

  9. asp.net MVC  Ajax.BeginForm 异步上传图片的问题

    当debug到这里,你们就发现不管是 Request.Files["Upload"]亦或 Request.Files[0] 都不会取到文件流. 这就是我要说的,当使用Ajax.Be ...

随机推荐

  1. How to Disable Strict SQL Mode in MySQL 5.7

    If your app was written for older versions of MySQL and is not compatible with strict SQL mode in My ...

  2. jQuery Mobile入门

    转:http://www.cnblogs.com/linjiqin/archive/2011/07/17/2108896.html 简介:jQuery Mobile框架可以轻松的帮助我们实现非常好看的 ...

  3. 知乎一道前端面试题详解,关于this的使用

    请说明要输出正确的myName的值要如何修改程序?并解释原因 foo = function(){ this.myName = "Foo function."; } foo.prot ...

  4. django 基础篇

    jdango 简介: 一个可以使Web开发工作愉快并且高效的Web开发框架. 使用Django,使你能够以 小的代价构建和维护高质量的Web应用. Python的WEB框架有Django.Tornad ...

  5. py-faster-rcnn几个辅助脚本

    py-faster-rcnn本身代码很棒. 不过使用它的时候,还是需要自己写一些脚本,作为辅助. 1 所有.py文件顶部添加utf8编码声明.因为有时候需要添加中文注释,不声明编码会报错 #inser ...

  6. UVA227

    步骤:1.把输入的数字和空格保存.(这里用到gets函数读取整行)2.定位空格.3.输入指令. #include<stdio.h> #include<string.h> ][] ...

  7. 2016福州大学软件工程Beta阶段团队作业成绩汇总

    1.评分规则 本次Beta阶段团队作业评分方法如下: 团队得分=[[7次scrum过程评分+(小组互评得分+教师评分)/2]/2],其中过程.小组.教师各30分 说明:由于没有规定提交团队贡献比,因此 ...

  8. PHP 进程间通信——消息队列(msg_queue)

    PHP 进程间通信--消息队列 本文不涉及PHP基础库安装.详细安装说明,请参考官网,或期待后续博客分享. 1.消息队列函数准备 <?php//生成一个消息队列的key$msg_key = ft ...

  9. Linux虚拟机中配置JDK环境变量

    前提准备: 1,安装好Linux系统 2,下载好可以将文件传输到Linux系统工具例如:WinSCP 3,在windows中下载Linux版JDK: http://download.oracle.co ...

  10. 12月8日phpcms添加子栏目后的读取

    一个栏目下面如果没有子栏目,那么它调用的模板就是列表页模板(及list_为前缀的模板):如果一个栏目下面有子栏目,那么它调用的就是栏目首页模板(category_为前缀的模板). 所以,当你这个栏目添 ...