MVC前台——的图片上传界面
public ActionResult Photo()
{
var list = DBHlper.GetList<PengYouQuan>("select * from PengYouQuan");
return View(list);
}
@model IEnumerable<_6._15ZuoyeMvc.Models.PengYouQuan>
@{
ViewBag.Title = "Photo";
}
ViewBag.Title = "Photo";
}
<h2>Photo</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.PyqId)
</th>
<th>
@Html.DisplayNameFor(model => model.NeiRong)
</th>
<th>
@Html.DisplayNameFor(model => model.Photo)
</th>
<th></th>
</tr>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.PyqId)
</th>
<th>
@Html.DisplayNameFor(model => model.NeiRong)
</th>
<th>
@Html.DisplayNameFor(model => model.Photo)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.PyqId)
</td>
<td>
@Html.DisplayFor(modelItem => item.NeiRong)
</td>
<td>
<img src="~/Image/1.png.jpg" style="width:150px;height:150px;" alt="@item.Photo" />
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
<tr>
<td>
@Html.DisplayFor(modelItem => item.PyqId)
</td>
<td>
@Html.DisplayFor(modelItem => item.NeiRong)
</td>
<td>
<img src="~/Image/1.png.jpg" style="width:150px;height:150px;" alt="@item.Photo" />
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
@{
ViewBag.Title = "Photo";
}
ViewBag.Title = "Photo";
}
<h2>Photo</h2>
<script src="~/Scripts/jquery-3.3.1.js"></script>
<script src="~/Scripts/jquery-3.3.1.js"></script>
<div class="leftImage">
<input type="file" id="picAjax" onclick="Choose();" class="customButton" />
<span id="uploadInfo"></span>
<input type="button" id="submitPic" class="customButton" value="上传" />
</div>
<div class="rightImage">
<img id="selImg" src="" alt="" />
</div>
<input type="file" id="picAjax" onclick="Choose();" class="customButton" />
<span id="uploadInfo"></span>
<input type="button" id="submitPic" class="customButton" value="上传" />
</div>
<div class="rightImage">
<img id="selImg" src="" alt="" />
</div>
<script>
$(function () {
})
function Choose() {
if (true) {
var picString = "";
$("#picAjax").change(function (e) {
var file = e.delegateTarget.files[0];
if (file.type == 'image/jpeg' || file.type == 'image/png') {
$("#uploadInfo").text("图片格式正确,请点击提交按钮");
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (ret) {
picString = reader.result;
//预览图片
$("#selImg").attr({ "src": picString });
}
}
else {
$("#uploadInfo").text("请上传jpg或png格式的图片!");
}
});
}
}
if (true) {
var picString = "";
$("#picAjax").change(function (e) {
var file = e.delegateTarget.files[0];
if (file.type == 'image/jpeg' || file.type == 'image/png') {
$("#uploadInfo").text("图片格式正确,请点击提交按钮");
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (ret) {
picString = reader.result;
//预览图片
$("#selImg").attr({ "src": picString });
}
}
else {
$("#uploadInfo").text("请上传jpg或png格式的图片!");
}
});
}
}
</script>