___简单的MVC单个图片上传预览

js:


$("#btnImg").click(function () {
$("#form0").ajaxSubmit({
url: "/Student/Img",
type: "post",
success: Math,
})
return false;
})
function Math(data) {
$("#Imgurl").val(data);
$("#result").html(" <img src='" + data + "' style='80px;height:60px' />")
}

html:

td>头像</td>
<td><input id="ImgMath" type="file" name="ImgMath" /><input id="btnImg" type="button" value="预览" /></td>
@Html.Hidden("Imgurl")
<td><span id="result"></span></td>

coller:

[HttpPost]
public ActionResult Img()
{
var Maph = Request.Files["ImgMath"];
string ImgPath ="/Content/img/" + Maph.FileName;
string Ser_Img = Request.MapPath(ImgPath);
Maph.SaveAs(Ser_Img);
return Content(ImgPath);
}

原文地址:https://www.cnblogs.com/100234ltf/p/9872657.html