尝试编写上传代码但显示错误 [英] trying to write code for upload but showing error
本文介绍了尝试编写上传代码但显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里我收到的错误就像
here i am getting error like
c:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\root\4d627a43\ab2fd5d9\App_Web_index.cshtml.32644dcb.zykik1o6.0.cs(36): error CS1001: Identifier expected
controler代码
controler code
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Up(HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file == null)
{
ModelState.AddModelError("File", "Please Upload Your file");
}
else if (file.ContentLength > 0)
{
int MaxContentLength = 1024 * 1024 * 3; //3 MB
string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".pdf" };
if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
{
ModelState.AddModelError("File", "Please file of type: " + string.Join(", ", AllowedFileExtensions));
}
else if (file.ContentLength > MaxContentLength)
{
ModelState.AddModelError("File", "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB");
}
else
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Upload"), fileName);
file.SaveAs(path);
ModelState.Clear();
ViewBag.Message = "File uploaded successfully. File path : ~/Upload/" + fileName;
}
}
}
return View();
}
}
}
推荐答案
编译错误CS1001意味着你没有提供Enum的标识符,参数名称等...
查看此链接以获取更多信息。 CS1001错误
Compilation Error CS1001 means you did not supply an identifier for an Enum, parameter name, etc...
Check this link for more info. CS1001 Error
这篇关于尝试编写上传代码但显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文