[HttpGet]
public HttpResponseMessage GetImage()
{
//文件路径
var path = HostingEnvironment.MapPath("~/App_Data/5.jpg");
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
Image img = Image.FromStream(fileStream);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(ms.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "5.jpg"//文件名
};
return result;
}
标签归档:.Net
Html.BeginForm add class attribute
@Html.BeginForm("DoSearch", "Search", FormMethod.Post, new { @class = "myclass"})
Add/remove site map node using MvcSiteMapProvider
add new CustomSiteMapProvider
public class CustomSiteMapProvider : DefaultSiteMapProvider { public void ClearSiteMap() { Clear(); } }
Change web.config file to use the custom sitemapprovider instead of DefaultSiteMapProvider.
When node changes, add
((CustomSiteMapProvider)SiteMap.Provider).ClearSiteMap();
.net mvc display image from file
controller:
public ActionResult Image(string id)
{
var dir = Server.MapPath("/Images");
var path = Path.Combine(dir, id + ".jpg");
return base.File(path, "image/jpeg");
}
view:
<img src="@Url.Action("Image", new { id= Model.Guid })" alt="@Model.Name" width="300" >
IIS .net upload large file congif
IIS 7.x,
?<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="2147483648" /> </requestFiltering> </security> </system.webServer>
IIS 6.0
?<system.web> <httpRuntime maxRequestLength="2097151" /> </system.web>
MVC3-Razor输出Html
输出HTML代码(包含标签):直接输出,
string html = "文本";
@html
输出HTML内容(不包含标签):有两种方法,
第一种:
IHtmlString html=new HtmlString("文本");
@html ;
第二种:
string html = "文本";
@Html.Raw(html);