【发布时间】:2020-07-01 14:19:30
【问题描述】:
当我获取上传的图片名称时出现错误,请参阅控制台
我在数据库中成功上传了图片,但现在我想在点击编辑按钮时获取上传的图片名称
student.cs
namespace AxInMvc.Models
{
using System;
using System.Collections.Generic;
public partial class student
{
public int studentid { get; set; }
public string studentname { get; set; }
public string studentimage { get; set; }
HomeController.cs
public JsonResult GetbyID(int studentid)
{
return Json(InsAjaxEntities.students.FirstOrDefault(x => x.studentid == studentid), JsonRequestBehavior.AllowGet);
}
索引.cshtml
<div class="form-group">
<label for="studentname"><strong>StudentName:</strong></label>
<input type="text" id="studentname" class="form-control" />
</div>
<div class="form-group">
<label for="studentimage"><strong>StudentImage:</strong></label>
<input id="studentimage" type="file" name="file"/>
</div>
@section scripts {
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script type="text/javascript">
function getbyID(studentid) {
debugger
$.ajax({
type: "GET",
url: "/Home/GetbyID" + "?" + "studentid=" + studentid,
contentType: "application/json;charset=UTF-8",
dataType: "json",
success: function (result) {
debugger
$('#studentid').val(result.studentid);
$('#studentname').val(result.studentname);
$('#studentimage').val(result.studentimage); //I think here I am getting error here
$('#myModal').modal('show'); //here I am get the data and then updating the data
$('#btnUpdate').show();
$('#btnAdd').hide();
},
error: function (errormessage) {
debugger
console.log(JSON.stringify(errormessage));
}
});
}
当我得到上传的图片名称时会报错:
https://i.stack.imgur.com/ssUug.png
请帮忙?
【问题讨论】:
标签: javascript jquery ajax asp.net-mvc