<div>
<form action="fileUpload" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>请选择文件</td>
<td><input type="file" name="Excelname" value="" /></td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="name" value="" /></td>
</tr>
<tr>
<td>类:</td>
<td><input type="text" name="lei" value="" /></td>
</tr>
<tr>
<td>班级:</td>
<td><input type="text" name="lei" value="" /></td>
</tr>
<tr>
<td>性别:</td>
<td><input id="Radio1" type="radio" />男<input id="Radio1" type="radio" />女</td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name="name" value="" /></td>
</tr>
<tr>
<td><input type="submit" name="name" value="添加" /></td>
</tr>
</table>
</form>
</div>
public ActionResult fileUpload(HttpPostedFileBase Excelname, MVCmodel n)
{
if (Excelname == null)
{
return View();
}
string Fname = Server.MapPath("/EXCEL/");
if (!Directory.Exists(Fname))
{
Directory.CreateDirectory(Fname);
}
string foldname = Path.GetFileName(Excelname.FileName);
string Fnewname = string.Format("{0}.{1}", Guid.NewGuid().ToString(), foldname.Split('.')[1]);
Excelname.SaveAs(Fname+Fnewname);
sModel m = new sModel();
m.Name = n.Name;
m.AradeNo = m.AradeNo;
m.ClassNo = n.ClassNo;
m.Sex = n.Sex;
m.Age = n.Age;
m.FileName = Fnewname;
var data = new BLL.sBLL().addinfos(m);
if (data > 0)
{
return Content("<script>alert('上传成功');location.href='showList'</script>");
}
else
{
return Content("<script>上传失败</script>");
}
}