view视图代码
控制器代码:
记得需要引用
using systm.IO;
public ActionResult UsersAdd(UserTableInfo A, HttpPostedFileBase file)
{
if (file != null)
{
string path = Server.MapPath("~/IMG/") + Path.GetFileName(file.FileName);
file.SaveAs(path);
A.UserImg = "/IMG/" + Path.GetFileName(file.FileName);
A.UserCode = Guid.NewGuid();
A.CreateTime = DateTime.Now;
string aa = JsonConvert.SerializeObject(bll.Add(A));
int aaa = aa.Length;
if (aaa > 0)
{
return Content("<script>alert('添加成功');window.parent.location.reload();</script>");
}
else
{
return Content("<script>alert('添加失败');window.parent.location.reload();</script>");
}
}
else
{
return Content("<script>alert('请选择图片')</script>");
}
}