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);
}
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论