asp.net mvc中动态表单上传头像
因为刚学习mvc,所以在做例子的时候出现问题,不知道怎么解决,所以请大家帮下忙,辛苦了.
在UploadController.cs中
//
// GET: /Upload/
public string FacePic = "Upload/default_face.gif";
public ActionResult Index()
{
ViewData["FacePic"] = FacePic;
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadFace()
{
foreach (string fn in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[fn];
if (!this.HasFile(hpf)) continue;
this.FacePic = this.SaveFile(hpf);
break;
}
return Index();
}
private bool SaveFile(HttpPostedFileBase hpf)
{
string path = Server.MapPath("~/Upload");
string filename = hpf.FileName.Substring(hpf.FileName.LastIndexOf("\\") + 1);
hpf.SaveAs(path + filename);
return "/Upload/" + filename;
}
private bool HasFile(HttpPostedFileBase hpf)
{
return hpf != null && hpf.ContentLength > 0;
}
}
出现的问题是:this.SaveFile(hpf);
"/Upload/" + filename;
出现红色下划线,请问怎么解决呢?