我希望有人可以帮助在 WebMatrix2 中添加选择字段。我希望能够在 App_data > UploadedFiles > folderA、foldeB 等中添加文件夹,这些文件夹用文件夹 A、文件夹 B 等填充选择字段。
我遵循了“在 ASP.NET 网页(Razor)站点中处理文件”,该代码确实有效,但它只显示了如何将多个文件添加到特定目录(UploadedFiles)。我希望能够根据下拉菜单保存文件。
这是我到目前为止所拥有的:
@using Microsoft.Web.Helpers;
@{
var message = "";
if (IsPost) {
var fileName = "";
var fileSavePath = "";
int numFiles = Request.Files.Count;
int uploadedCount = 0;
for(int i =0; i < numFiles; i++) {
var uploadedFile = Request.Files[i];
if (uploadedFile.ContentLength > 0) {
fileName = Path.GetFileName(uploadedFile.FileName);
fileSavePath = Server.MapPath("~/App_Data/UploadedFiles/" +fileName);
uploadedFile.SaveAs(fileSavePath);
uploadedCount++;
}
}
Response.Redirect("videoList.cshtml");
}
}
<form method="post" enctype="multipart/form-data" action="">
<div>
<h1>File Upload - Multiple-File Example</h1>
@if (!IsPost) {
@FileUpload.GetHtml(
initialNumberOfFiles:2,
allowMoreFilesToBeAdded:false,
includeFormTag:false,
addText:"Add another file",
uploadText:"Upload")
}
</div>
<input type="submit" value="Upload" />
</form>
先感谢您