【发布时间】:2020-06-23 03:23:35
【问题描述】:
我想在我的图片文件夹中上传图片,现在我的图片插入表格而不是图片文件夹
Controller.cs
[HttpPost]
public ActionResult Create(student student, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file != null)
{
file.SaveAs(HttpContext.Server.MapPath("~/Images/")
+ file.FileName);
student.studentimage = file.FileName;
}
InsAjaxEntities.students.Add(student);
InsAjaxEntities.SaveChanges();
return RedirectToAction("Index");
}
return View(student);
}
create.cshtml
@using (Html.BeginForm("Create", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="row">
<div class="form-group col-lg-10">
<label class="control-label col-lg-2"><strong>StudentImage:</strong></label>
<input type="file" id="studentimage" />
</div>
</div>
}
@section scripts {
<div>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
$('#button').click(function () {
var stud = {
studentimage: $('#studentimage').val()
};
$.ajax({
url: '/Home/Create',
data: JSON.stringify(stud),
dataType: "json",
type: 'POST',
contentType: "application/json;charset=utf-8",
success: function (data) {
debugger
alert('success', data);
},
error: function (x, y, z) {
debugger
}
});
表格
public string studentimage { get; set; }
以这种方式查看我的图像存储:
我正在使用ajax将图像存储在文件夹中,但图像不存储在文件夹中
我的图像没有存储在我想要存储在文件夹中的文件夹中?
如何在文件夹中存储图片?
我想将图像存储在正确的路径而不是假路径中?
【问题讨论】:
标签: javascript jquery ajax asp.net-mvc