display the multiple images from database using array
Hi Guys I am trying to Display the images from database I save the images in the database but it not display any thing how can i fix this here in my Code
this is my model view
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Archive.Models
{
public class Inbox
{
[Key]
public int Id { get; set; }
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public ApplicationUser User { get; set; }
public object UserId { get; internal set; }
}
}
and here details
namespace Archive.Models
{
public class AllFiles
{
public int Id { get; set; }
public string ContentType{ get; set; }
public byte Imagebytes { get; set; }
}
}
here i Convert
using System.Web;
using System.IO;
namespace FileUpload.Service
{
public class FileUploadService
{
// GET: AllFiles
public void saveFileDetails(HttpPostedFileBase file)
{
AllFiles newfile = new AllFiles();
newfile.ContentType = file.ContentType;
newfile.Imagebytes = ConvertToBytes(file);
ApplicationDbContext db = new ApplicationDbContext();
{
db.AllFiless.Add(newfile);
db.SaveChanges();
}
}
public byte ConvertToBytes(HttpPostedFileBase file)
{
byte imagebytes = null;
BinaryReader reader = new BinaryReader(file.InputStream);
imagebytes = reader.ReadBytes((int)file.ContentLength);
return imagebytes;
}
}
}
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
FileUploadService service = new FileUploadService();
foreach (var item in model.Files)
{
service.saveFileDetails(item);
}
var max = new Inbox();
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
and this is my view details
@foreach(var image in Model)
{
var base64 = Convert.ToBase64String(image.Files);
var imgSrc = String.Format("data:{0};base64,{1}",image.ContentType ,base64);
<img src="@imgSrc"/>
}
i am try to display images here but is not show up what is problem guys please guys i am trying this so hard i asked here but i did't get the images
the image in database it saved like this
here
c# asp.net-mvc razor model-view-controller asp.net-mvc-5
|
show 1 more comment
Hi Guys I am trying to Display the images from database I save the images in the database but it not display any thing how can i fix this here in my Code
this is my model view
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Archive.Models
{
public class Inbox
{
[Key]
public int Id { get; set; }
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public ApplicationUser User { get; set; }
public object UserId { get; internal set; }
}
}
and here details
namespace Archive.Models
{
public class AllFiles
{
public int Id { get; set; }
public string ContentType{ get; set; }
public byte Imagebytes { get; set; }
}
}
here i Convert
using System.Web;
using System.IO;
namespace FileUpload.Service
{
public class FileUploadService
{
// GET: AllFiles
public void saveFileDetails(HttpPostedFileBase file)
{
AllFiles newfile = new AllFiles();
newfile.ContentType = file.ContentType;
newfile.Imagebytes = ConvertToBytes(file);
ApplicationDbContext db = new ApplicationDbContext();
{
db.AllFiless.Add(newfile);
db.SaveChanges();
}
}
public byte ConvertToBytes(HttpPostedFileBase file)
{
byte imagebytes = null;
BinaryReader reader = new BinaryReader(file.InputStream);
imagebytes = reader.ReadBytes((int)file.ContentLength);
return imagebytes;
}
}
}
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
FileUploadService service = new FileUploadService();
foreach (var item in model.Files)
{
service.saveFileDetails(item);
}
var max = new Inbox();
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
and this is my view details
@foreach(var image in Model)
{
var base64 = Convert.ToBase64String(image.Files);
var imgSrc = String.Format("data:{0};base64,{1}",image.ContentType ,base64);
<img src="@imgSrc"/>
}
i am try to display images here but is not show up what is problem guys please guys i am trying this so hard i asked here but i did't get the images
the image in database it saved like this
here
c# asp.net-mvc razor model-view-controller asp.net-mvc-5
How are those images saved? Blobs in the Database? Files in the FileSystem? Is the folder public/do you got a HTTP handler to serve those images to WebBrowsers?
– Christopher
Nov 12 '18 at 16:59
Where is the GET action method code for the view where you are trying to display the images ?
– Shyju
Nov 12 '18 at 17:40
i am trying to display the images in a inbox controller i don't have a get action to display how can i do that
– jmal hassn
Nov 12 '18 at 17:47
For the request, you need a GET action which gets the data and pass it to the view. Is your current code properly saving the data ? I see manyApplicationDbContext
objects inside the save code.
– Shyju
Nov 12 '18 at 18:29
Shyju can you help me do this please bro
– jmal hassn
Nov 12 '18 at 18:51
|
show 1 more comment
Hi Guys I am trying to Display the images from database I save the images in the database but it not display any thing how can i fix this here in my Code
this is my model view
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Archive.Models
{
public class Inbox
{
[Key]
public int Id { get; set; }
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public ApplicationUser User { get; set; }
public object UserId { get; internal set; }
}
}
and here details
namespace Archive.Models
{
public class AllFiles
{
public int Id { get; set; }
public string ContentType{ get; set; }
public byte Imagebytes { get; set; }
}
}
here i Convert
using System.Web;
using System.IO;
namespace FileUpload.Service
{
public class FileUploadService
{
// GET: AllFiles
public void saveFileDetails(HttpPostedFileBase file)
{
AllFiles newfile = new AllFiles();
newfile.ContentType = file.ContentType;
newfile.Imagebytes = ConvertToBytes(file);
ApplicationDbContext db = new ApplicationDbContext();
{
db.AllFiless.Add(newfile);
db.SaveChanges();
}
}
public byte ConvertToBytes(HttpPostedFileBase file)
{
byte imagebytes = null;
BinaryReader reader = new BinaryReader(file.InputStream);
imagebytes = reader.ReadBytes((int)file.ContentLength);
return imagebytes;
}
}
}
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
FileUploadService service = new FileUploadService();
foreach (var item in model.Files)
{
service.saveFileDetails(item);
}
var max = new Inbox();
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
and this is my view details
@foreach(var image in Model)
{
var base64 = Convert.ToBase64String(image.Files);
var imgSrc = String.Format("data:{0};base64,{1}",image.ContentType ,base64);
<img src="@imgSrc"/>
}
i am try to display images here but is not show up what is problem guys please guys i am trying this so hard i asked here but i did't get the images
the image in database it saved like this
here
c# asp.net-mvc razor model-view-controller asp.net-mvc-5
Hi Guys I am trying to Display the images from database I save the images in the database but it not display any thing how can i fix this here in my Code
this is my model view
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Archive.Models
{
public class Inbox
{
[Key]
public int Id { get; set; }
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public ApplicationUser User { get; set; }
public object UserId { get; internal set; }
}
}
and here details
namespace Archive.Models
{
public class AllFiles
{
public int Id { get; set; }
public string ContentType{ get; set; }
public byte Imagebytes { get; set; }
}
}
here i Convert
using System.Web;
using System.IO;
namespace FileUpload.Service
{
public class FileUploadService
{
// GET: AllFiles
public void saveFileDetails(HttpPostedFileBase file)
{
AllFiles newfile = new AllFiles();
newfile.ContentType = file.ContentType;
newfile.Imagebytes = ConvertToBytes(file);
ApplicationDbContext db = new ApplicationDbContext();
{
db.AllFiless.Add(newfile);
db.SaveChanges();
}
}
public byte ConvertToBytes(HttpPostedFileBase file)
{
byte imagebytes = null;
BinaryReader reader = new BinaryReader(file.InputStream);
imagebytes = reader.ReadBytes((int)file.ContentLength);
return imagebytes;
}
}
}
and here is my Controller
public async Task<ActionResult> Create(Inbox model)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
FileUploadService service = new FileUploadService();
foreach (var item in model.Files)
{
service.saveFileDetails(item);
}
var max = new Inbox();
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
and this is my view details
@foreach(var image in Model)
{
var base64 = Convert.ToBase64String(image.Files);
var imgSrc = String.Format("data:{0};base64,{1}",image.ContentType ,base64);
<img src="@imgSrc"/>
}
i am try to display images here but is not show up what is problem guys please guys i am trying this so hard i asked here but i did't get the images
the image in database it saved like this
here
c# asp.net-mvc razor model-view-controller asp.net-mvc-5
c# asp.net-mvc razor model-view-controller asp.net-mvc-5
edited Nov 13 '18 at 9:06
jmal hassn
asked Nov 12 '18 at 16:57
jmal hassnjmal hassn
86
86
How are those images saved? Blobs in the Database? Files in the FileSystem? Is the folder public/do you got a HTTP handler to serve those images to WebBrowsers?
– Christopher
Nov 12 '18 at 16:59
Where is the GET action method code for the view where you are trying to display the images ?
– Shyju
Nov 12 '18 at 17:40
i am trying to display the images in a inbox controller i don't have a get action to display how can i do that
– jmal hassn
Nov 12 '18 at 17:47
For the request, you need a GET action which gets the data and pass it to the view. Is your current code properly saving the data ? I see manyApplicationDbContext
objects inside the save code.
– Shyju
Nov 12 '18 at 18:29
Shyju can you help me do this please bro
– jmal hassn
Nov 12 '18 at 18:51
|
show 1 more comment
How are those images saved? Blobs in the Database? Files in the FileSystem? Is the folder public/do you got a HTTP handler to serve those images to WebBrowsers?
– Christopher
Nov 12 '18 at 16:59
Where is the GET action method code for the view where you are trying to display the images ?
– Shyju
Nov 12 '18 at 17:40
i am trying to display the images in a inbox controller i don't have a get action to display how can i do that
– jmal hassn
Nov 12 '18 at 17:47
For the request, you need a GET action which gets the data and pass it to the view. Is your current code properly saving the data ? I see manyApplicationDbContext
objects inside the save code.
– Shyju
Nov 12 '18 at 18:29
Shyju can you help me do this please bro
– jmal hassn
Nov 12 '18 at 18:51
How are those images saved? Blobs in the Database? Files in the FileSystem? Is the folder public/do you got a HTTP handler to serve those images to WebBrowsers?
– Christopher
Nov 12 '18 at 16:59
How are those images saved? Blobs in the Database? Files in the FileSystem? Is the folder public/do you got a HTTP handler to serve those images to WebBrowsers?
– Christopher
Nov 12 '18 at 16:59
Where is the GET action method code for the view where you are trying to display the images ?
– Shyju
Nov 12 '18 at 17:40
Where is the GET action method code for the view where you are trying to display the images ?
– Shyju
Nov 12 '18 at 17:40
i am trying to display the images in a inbox controller i don't have a get action to display how can i do that
– jmal hassn
Nov 12 '18 at 17:47
i am trying to display the images in a inbox controller i don't have a get action to display how can i do that
– jmal hassn
Nov 12 '18 at 17:47
For the request, you need a GET action which gets the data and pass it to the view. Is your current code properly saving the data ? I see many
ApplicationDbContext
objects inside the save code.– Shyju
Nov 12 '18 at 18:29
For the request, you need a GET action which gets the data and pass it to the view. Is your current code properly saving the data ? I see many
ApplicationDbContext
objects inside the save code.– Shyju
Nov 12 '18 at 18:29
Shyju can you help me do this please bro
– jmal hassn
Nov 12 '18 at 18:51
Shyju can you help me do this please bro
– jmal hassn
Nov 12 '18 at 18:51
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266781%2fdisplay-the-multiple-images-from-database-using-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266781%2fdisplay-the-multiple-images-from-database-using-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
How are those images saved? Blobs in the Database? Files in the FileSystem? Is the folder public/do you got a HTTP handler to serve those images to WebBrowsers?
– Christopher
Nov 12 '18 at 16:59
Where is the GET action method code for the view where you are trying to display the images ?
– Shyju
Nov 12 '18 at 17:40
i am trying to display the images in a inbox controller i don't have a get action to display how can i do that
– jmal hassn
Nov 12 '18 at 17:47
For the request, you need a GET action which gets the data and pass it to the view. Is your current code properly saving the data ? I see many
ApplicationDbContext
objects inside the save code.– Shyju
Nov 12 '18 at 18:29
Shyju can you help me do this please bro
– jmal hassn
Nov 12 '18 at 18:51