在MonoRail中文件上传很简单,使用智能绑定方式后直接用HttpPostedFile类就可以进行操作了
vm文件:
Controller文件:
注意:此Controller类需要从SmartDispatcherController继承
当然将vm文件的第四行换成:
vm文件:
1
<
h1
align
="center"
>
Upload photo
</
h1
>
2 < form action ="upload.rails" method ="post" enctype="multipart/form-data">
3
4 $FormHelper.FileField("additionalFile")
5 < input name ="act" type ="submit" value ="Upload" >
6 </ form >
7
特别注意其中黑体的部分
2 < form action ="upload.rails" method ="post" enctype="multipart/form-data">
3
4 $FormHelper.FileField("additionalFile")
5 < input name ="act" type ="submit" value ="Upload" >
6 </ form >
7
Controller文件:
public
void
upload(HttpPostedFile additionalFile)
{
additionalFile.SaveAs("c://" + additionalFile.FileName.Substring(additionalFile.FileName.LastIndexOf("//") + 1));
this.CancelView();
}
使用的是智能绑定的方式
{
additionalFile.SaveAs("c://" + additionalFile.FileName.Substring(additionalFile.FileName.LastIndexOf("//") + 1));
this.CancelView();
}
注意:此Controller类需要从SmartDispatcherController继承
当然将vm文件的第四行换成:
<
input
type
=file
name
="additionalFile"
/>
也是可以的