当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net MVC实现简单的上传功能

asp.net MVC实现简单的上传功能

2017年12月12日  | 移动技术网IT编程  | 我要评论
方法一: home/index.aspx中的代码 复制代码 代码如下: <% using (html.beginform("up","home",formmethod
方法一:
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);
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网