asp.net MVC實(shí)現(xiàn)簡(jiǎn)單的上傳功能
更新時(shí)間:2009年11月30日 21:01:14 作者:
MVC中上傳變得越來(lái)越容易,可是對(duì)于新手這個(gè)也還是不知道如何實(shí)現(xiàn),以下方式實(shí)現(xiàn)MVC的上傳功能,以下2種方法都是可以實(shí)現(xiàn)的,其中的代碼參考了藍(lán)色小鋪和重典的文章。
方法一:
Home/Index.aspx中的代碼
<% using (Html.BeginForm("up","Home",FormMethod.Post,new{enctype="multipart/form-data"})) {%>
<input type="file" name="upfile" />
<input type ="submit" name ="upload" value ="上傳" />
<%} %>
Homecontroller中的代碼
[code]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult up(HttpPostedFileBase upfile)
{
if (upfile != null)
{
if (upfile.ContentLength > 0)
{
upfile.SaveAs("d:\\7.jpg");
}
}
return RedirectToAction("Index");
}
方法二:
Home/Index.aspx中的代碼
<form action="<%=Url.Action("upload2") %>" enctype="multipart/form-data" method="post">
<input name="up1" type="file" /><input type="submit" />
</form>
Homecontroller中的代碼
public ActionResult upload2(HttpPostedFileBase up1)
{
up1.SaveAs("d:\\8.jpg");
return Content(up1.FileName);
}
Home/Index.aspx中的代碼
復(fù)制代碼 代碼如下:
<% using (Html.BeginForm("up","Home",FormMethod.Post,new{enctype="multipart/form-data"})) {%>
<input type="file" name="upfile" />
<input type ="submit" name ="upload" value ="上傳" />
<%} %>
Homecontroller中的代碼
[code]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult up(HttpPostedFileBase upfile)
{
if (upfile != null)
{
if (upfile.ContentLength > 0)
{
upfile.SaveAs("d:\\7.jpg");
}
}
return RedirectToAction("Index");
}
方法二:
Home/Index.aspx中的代碼
復(fù)制代碼 代碼如下:
<form action="<%=Url.Action("upload2") %>" enctype="multipart/form-data" method="post">
<input name="up1" type="file" /><input type="submit" />
</form>
Homecontroller中的代碼
復(fù)制代碼 代碼如下:
public ActionResult upload2(HttpPostedFileBase up1)
{
up1.SaveAs("d:\\8.jpg");
return Content(up1.FileName);
}
您可能感興趣的文章:
- SpringMVC文件上傳 多文件上傳實(shí)例
- Spring MVC中上傳文件實(shí)例
- asp.net MVC實(shí)現(xiàn)無(wú)組件上傳圖片實(shí)例介紹
- Asp.net實(shí)現(xiàn)MVC處理文件的上傳下載功能實(shí)例教程
- 用Fine Uploader+ASP.NET MVC實(shí)現(xiàn)ajax文件上傳[代碼示例]
- 用Html5與Asp.net MVC上傳多個(gè)文件的實(shí)現(xiàn)代碼
- SpringMVC上傳圖片與訪問(wèn)
- ASP.NET?MVC5實(shí)現(xiàn)文件上傳與地址變化處理(5)
- 使用jQuery.form.js/springmvc框架實(shí)現(xiàn)文件上傳功能
- mvc file控件無(wú)刷新異步上傳操作源碼
相關(guān)文章
ASP.NET Core 2.0中Razor頁(yè)面禁用防偽令牌驗(yàn)證
在這篇短文中,我將向您介紹如何ASP.NET Core2.0 Razor頁(yè)面中禁用防偽令牌驗(yàn)證,對(duì)此有興趣的朋友參考學(xué)習(xí)下吧。2018-01-01
在?ASP.NET?Core?中使用?HTTP?標(biāo)頭傳播詳情
這篇文章主要介紹了在?ASP.NET?Core?中使用?HTTP?標(biāo)頭傳播詳情,文章通過(guò),我們創(chuàng)建?ServerA、ServiceB?兩個(gè)?Web?API?項(xiàng)目展開(kāi)內(nèi)容,需要的朋友可以參考一下2022-04-04
ASP.NET設(shè)計(jì)網(wǎng)絡(luò)硬盤(pán)之下載或在線查看實(shí)現(xiàn)代碼
在目錄瀏覽中,如果選擇的是一個(gè)文件,單擊“打開(kāi)”按鈕就可以進(jìn)行文件下載2012-10-10
淺談Asp.net Mvc之Action如何傳多個(gè)參數(shù)的方法
本篇文章主要介紹了Asp.net Mvc之Action如何傳多個(gè)參數(shù)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-08-08
Asp.Net 動(dòng)態(tài)頁(yè)面轉(zhuǎn)靜態(tài)頁(yè)面主要代碼
關(guān)于在Asp.Net中動(dòng)態(tài)頁(yè)面轉(zhuǎn)靜態(tài)頁(yè)面的方法網(wǎng)上比較多。結(jié)合實(shí)際的需求,我在網(wǎng)上找了一些源代碼,并作修改?,F(xiàn)在把修改后的代碼以及說(shuō)明寫(xiě)一下。2009-12-12
asp.net mvc CodeFirst模式數(shù)據(jù)庫(kù)遷移步驟詳解
這篇文章主要為大家詳細(xì)介紹了asp.net mvc CodeFirst模式數(shù)據(jù)庫(kù)遷移步驟,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
在ASP.NET中支持?jǐn)帱c(diǎn)續(xù)傳下載大文件(ZT)源碼
這篇文章主要為大家介紹了在ASP.NET中如何做到支持?jǐn)帱c(diǎn)續(xù)傳下載大文件(ZT),需要的朋友可以參考下2014-07-07
VS2019中.NET如何實(shí)現(xiàn)打日志功能
本文主要介紹了VS2019中.NET如何實(shí)現(xiàn)打日志功能,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03

