i tried to uploadfie files to the database and it uploading well, but when i want to retriew the pdf files from the database it is showing on the view page can anyone help me
public ActionResult Add()
{
return View();
}
[HttpPost]
public ActionResult Add(Image imageModel)
{
string fileName = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName);
string extension = Path.GetExtension(imageModel.ImageFile.FileName);
fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
imageModel.ImagePath = "~/Image/" + fileName;
fileName = Path.Combine(Server.MapPath("~/Image/"), fileName);
imageModel.ImageFile.SaveAs(fileName);
using (amsecgdbEntities db = new amsecgdbEntities())
{
string input = imageModel.ImagePath;
string[] parts1 = input.Split(new string[] { "/", "/", "_", "_", "]", "__ " }, StringSplitOptions.None);
for (int i = 0; i < parts1.Length; i++)
imageModel.billno = parts1[3];
string a = parts1[4];
string B = parts1[2];
String ww = B.Replace("EK", "IP");
imageModel.empid = ww;
string substr = a.Substring(1, 4);
string q = a.Substring(5, 2);
string w = a.Substring(7, 2);
imageModel.date = (substr + "-" + q + "-" + w);
string substr1 = a.Substring(9, 2);
string substr22 = a.Substring(11, 2);
string substr33 = a.Substring(13, 2);
imageModel.time = (substr1 + ":" + substr22 + ":" + substr33);
imageModel.name = parts1[8];
db.Images.Add(imageModel);
db.SaveChanges();
}
ModelState.Clear();
return Content("<script>alert('Inserted Successful'); window.location = './Dashboard';</script>");
}
@model ECG.Models.Image
@{
ViewBag.Title = "Add";
}
@using (Html.BeginForm("Add", "Image", FormMethod.Post, new {enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@*<h4>Image</h4>*@
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.Title, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ImagePath, new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="ImageFile" required></div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
@*<div>
@Html.ActionLink("Back to List", "Index")
</div>*@
@*@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}*@
[HttpGet]
public ActionResult View(int id)
{
Image imageModel = new Image();
using (amsecgdbEntities db = new amsecgdbEntities())
{
imageModel = db.Images.Where(x => x.ImageID == id).FirstOrDefault();
}
return View(imageModel);
}
@model ECG.Models.Image
@{
ViewBag.Title = "View";
}
<div style="border:double" >
<hr />
<dl class="dl-horizontal" >
<table border="10" cellpadding="10" style="width:100%;text-align:center;" align="center">
<tr>
<th style="text-align:center!important;">@Html.DisplayNameFor(model => model.empid)</th>
<th style="text-align:center!important;">@Html.DisplayNameFor(model => model.billno)</th>
<th style="text-align:center!important;"> @Html.DisplayNameFor(model => model.date)</th>
<th style="text-align:center!important;"> @Html.DisplayNameFor(model => model.time)</th>
<th style="text-align:center!important;">@Html.DisplayNameFor(model => model.name)</th>
<th style="text-align:center!important;">Report</th>
</tr>
<tr>
<td>
@Html.DisplayFor(model => model.empid)
</td>
<td>
@Html.DisplayFor(model => model.billno)
</td>
<td>
@Html.DisplayFor(model => model.date)
</td>
<td>
@Html.DisplayFor(model => model.time)
</td>
<td>
@Html.DisplayFor(model => model.name)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = Model.ImageID })
</td>|
</tr>
<table border="10" cellpadding="5" style="width:90%;">
<dd>
<tr style="text-align:center">
<img src="@Url.Content(Model.ImagePath)" style="width:100%;" height="550" multiple />
</tr>
</dd>
</table>
</table>
</dl>
</div>
<p>
@*@Html.ActionLink("Edit", "Edit", new { id = Model.ImageID }) |
@Html.ActionLink("Back to List", "Index")*@
</p>