摘要: https://packages.nuget.org/packages 阅读全文
posted @ 2012-12-14 15:46 火腿骑士 阅读(159) 评论(0) 推荐(0)
摘要: ASP.NET MVC3使用PagedList实现分页导航九月 3, 2012分页导航功能在Web应用中再常见不过了,本文介绍了近期项目开发过程中如何利用PagedList库实现数据条目的分页导航功能,项目其实很简单,就是实现一个简单的内容管理系统,具备增删改查的功能,采用了ASP.NET MVC3技术。使用NuGet包管理器,具体做法:右键项目的References => Manage NuGet Packages => 搜索PagedList安装。这里需要下载两个DLL,分别是PagedList.dll和PagedList.Mvc.dll,其中PagedList适用MVC2框架 阅读全文
posted @ 2012-12-14 15:36 火腿骑士 阅读(320) 评论(0) 推荐(0)
摘要: if(Request.Content.IsMimeMultipartContent()){ var streamProvider =newMultipartMemoryStreamProvider(); var task =Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(t =>//上传多个文件 { foreach(var item in streamProvider.Contents) { //do something }});public class UploadFileController : Ap 阅读全文
posted @ 2012-12-14 14:25 火腿骑士 阅读(443) 评论(0) 推荐(0)
摘要: 关于MVC4.0 WebAPI上传图片重命名以及图文结合MVC4.0 WebAPI上传后的图片默认以字符串bodypart结合Guid来命名,且没有文件后缀,为解决上传图片重命名以及图文结合发布的问题,在实体对象的处理上,可将图片属性定义为byte[]对象,至于图片的重命名,通过重写继承MultipartFormDataStreamProvider类来解决!参照API的官方文档,上传文件代码大致如下:public Task<HttpResponseMessage> PostFile() { HttpRequestMessage request = this.... 阅读全文
posted @ 2012-12-14 14:22 火腿骑士 阅读(467) 评论(0) 推荐(0)
摘要: 介绍 asp.net mvc 之 asp.net mvc 4.0 新特性之 Web API自宿主 web api宿主到 iis,通过 WebForm 提供 web api 服务通过 Web API 上传文件.net 4.5 带来的更方便的异步操作示例 1、自宿主 Web API 的 demo WebApiSelfHost/Program.cs/* * 自宿主 web api 的 demo * * 测试地址:http://localhost:123/api/hello */using System;using System.Collections.Generic;using System.Li. 阅读全文
posted @ 2012-12-14 14:19 火腿骑士 阅读(247) 评论(0) 推荐(0)
摘要: 作者:webabcd 介绍 asp.net mvc 之 asp.net mvc 4.0 新特性之 Web API开发一个 CRUD 的 Demo,服务端用 Web API,并使其支持 jsonp 协议,客户端用 jQuery示例 1、自定义一个 JsonMediaTypeFormatter,以支持 jsonp 协议 MyJsonFormatter.cs/* * 自定义一个 JsonMediaTypeFormatter,以支持 jsonp 协议 */using System;using System.Collections.Generic;using System.IO;using System 阅读全文
posted @ 2012-12-14 14:18 火腿骑士 阅读(189) 评论(0) 推荐(0)
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Mvc.Ajax;using System.IO;namespace MVC.Controllers{ /**/ /// <summary> /// Controller 类必须以字符串 "Controller" 做类名称的结尾,字符串 Controller 之前的字符串为 Controller 的名称,类中的方法名为 Acti 阅读全文
posted @ 2012-12-14 12:54 火腿骑士 阅读(133) 评论(0) 推荐(0)
摘要: 在 Controller 中我们可以使用 FileResult 向客户端发送文件。FileResultFileResult 是一个抽象类,继承自 ActionResult。在 System.Web.Mvc.dll 中,它有如上三个子类,分别以不同的方式向客户端发送文件。在实际使用中我们通常不需要直接实例化一个 FileResult 的子类,因为 Controller 类已经提供了六个 File 方法来简化我们的操作:protected internal FilePathResult File(string fileName, string contentType);protected inte 阅读全文
posted @ 2012-12-14 12:49 火腿骑士 阅读(180) 评论(0) 推荐(0)
摘要: 使用ASP.NET WEB API文档来上传异步文件原文作者:Henrik F Nielsen HTML窗体文件上传(在RFC1867中定义)是经典的上传内容到Web服务器机制,同时我知道的所有浏览器都支持它。这个博客展示了在ASP.NET Web API文档中,如何通过使用.NET 4和增强版的.NET4.5基于任务模式,来处理窗体文件的上传。 在使用ASP.NET Web API文档时,你可以通过托管来上传任意大小的文件。ASP.NET对于你上传的文件大小不能超过2G。 什么是HTML文件上传? 首先提醒自己的是HTML文件上传是什么。如果你不需要修改HTML上传文件,那么你可以跳过... 阅读全文
posted @ 2012-12-14 12:15 火腿骑士 阅读(451) 评论(0) 推荐(0)
摘要: asp.net mvc3局部页面使用方法详细说明:1.模板页:@RenderBody()占位符在模板页中加入@RenderBody()占位符,@RenderBody()所站的位置就是需要填充的内容的位置。如果想要应用模板页,须向内容页加入@{ Layout = "~/Views/Shared/_LogOnPartial.cshtml"; }~/Views/Shared/_LogOnPartial.cshtml为模板页位置,也可在配置默认值。2.局部页面:@RenderPage()需要调用局部页面的加入@RenderPage("~/Views/Home/_ViewP 阅读全文
posted @ 2012-12-14 12:08 火腿骑士 阅读(277) 评论(0) 推荐(0)
摘要: [TestClass] publicclassSampleTests { privateHttpSelfHostServer server =null; privatestring baseAddress =null; //Use TestInitialize to run code before running each test [TestInitialize()] publicvoidMyTestInitialize() { baseAddress =string.Format("http://{0}:9090",Environment.MachineName); . 阅读全文
posted @ 2012-12-14 09:47 火腿骑士 阅读(326) 评论(0) 推荐(0)
摘要: public void SetUp() { var config =newHttpSelfHostConfiguration("http://localhost:8080"); config.Routes.MapHttpRoute( "API Default","api/{controller}/{id}", new{ id =RouteParameter.Optional}); Server=newHttpSelfHostServer(config); Server.OpenAsync().Wait(); } 阅读全文
posted @ 2012-12-14 09:46 火腿骑士 阅读(237) 评论(0) 推荐(0)
摘要: Working console program:static voidMain(string[] args){ // Set up server configuration HttpSelfHostConfiguration config =newHttpSelfHostConfiguration("http://localhost:8080"); //Route Catches the GET PUT DELETE typical REST based interactions (add more if needed) config.Routes.MapHttpRoute 阅读全文
posted @ 2012-12-14 09:43 火腿骑士 阅读(325) 评论(0) 推荐(0)
摘要: ASP.NET MVC3 系列教程 – 新的Layout布局系统I:回忆MVC2当中MasterPage那些事code:<!------------Begin--------------><!-- Master文件 --><%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>Master head<asp:ContentPlaceHolder ID="MainContent" runat="server 阅读全文
posted @ 2012-12-14 00:06 火腿骑士 阅读(160) 评论(0) 推荐(0)