Image display in asp.net from sql











up vote
-1
down vote

favorite












I created a column named picture in my database and executed a query to insert and update a picture but when i try to display it in my asp.net site it does not show,only blank.In my database under the Picture column it says so it exists there but doesnt show?



 @foreach (var item in Model.EmployeeCollection)
{
<img alt="image" class="img-circle" src="@item.Photo">
}









share|improve this question
























  • What do you store in the database? Is it the image or is it a url?
    – Crowcoder
    Nov 12 at 10:05












  • it's the image that came from the url in the query
    – Em44
    Nov 12 at 10:07










  • That doesn't clear it up for me, what is an example value of item.Photo? A src attribute must be a url.
    – Crowcoder
    Nov 12 at 10:11










  • Photo is a byte
    – Em44
    Nov 12 at 10:14










  • That doesn't work because src is a url, not a byte array.
    – Crowcoder
    Nov 12 at 10:16















up vote
-1
down vote

favorite












I created a column named picture in my database and executed a query to insert and update a picture but when i try to display it in my asp.net site it does not show,only blank.In my database under the Picture column it says so it exists there but doesnt show?



 @foreach (var item in Model.EmployeeCollection)
{
<img alt="image" class="img-circle" src="@item.Photo">
}









share|improve this question
























  • What do you store in the database? Is it the image or is it a url?
    – Crowcoder
    Nov 12 at 10:05












  • it's the image that came from the url in the query
    – Em44
    Nov 12 at 10:07










  • That doesn't clear it up for me, what is an example value of item.Photo? A src attribute must be a url.
    – Crowcoder
    Nov 12 at 10:11










  • Photo is a byte
    – Em44
    Nov 12 at 10:14










  • That doesn't work because src is a url, not a byte array.
    – Crowcoder
    Nov 12 at 10:16













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I created a column named picture in my database and executed a query to insert and update a picture but when i try to display it in my asp.net site it does not show,only blank.In my database under the Picture column it says so it exists there but doesnt show?



 @foreach (var item in Model.EmployeeCollection)
{
<img alt="image" class="img-circle" src="@item.Photo">
}









share|improve this question















I created a column named picture in my database and executed a query to insert and update a picture but when i try to display it in my asp.net site it does not show,only blank.In my database under the Picture column it says so it exists there but doesnt show?



 @foreach (var item in Model.EmployeeCollection)
{
<img alt="image" class="img-circle" src="@item.Photo">
}






c# asp.net asp.net-mvc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 10:18









Liam

16k1676127




16k1676127










asked Nov 12 at 10:02









Em44

46




46












  • What do you store in the database? Is it the image or is it a url?
    – Crowcoder
    Nov 12 at 10:05












  • it's the image that came from the url in the query
    – Em44
    Nov 12 at 10:07










  • That doesn't clear it up for me, what is an example value of item.Photo? A src attribute must be a url.
    – Crowcoder
    Nov 12 at 10:11










  • Photo is a byte
    – Em44
    Nov 12 at 10:14










  • That doesn't work because src is a url, not a byte array.
    – Crowcoder
    Nov 12 at 10:16


















  • What do you store in the database? Is it the image or is it a url?
    – Crowcoder
    Nov 12 at 10:05












  • it's the image that came from the url in the query
    – Em44
    Nov 12 at 10:07










  • That doesn't clear it up for me, what is an example value of item.Photo? A src attribute must be a url.
    – Crowcoder
    Nov 12 at 10:11










  • Photo is a byte
    – Em44
    Nov 12 at 10:14










  • That doesn't work because src is a url, not a byte array.
    – Crowcoder
    Nov 12 at 10:16
















What do you store in the database? Is it the image or is it a url?
– Crowcoder
Nov 12 at 10:05






What do you store in the database? Is it the image or is it a url?
– Crowcoder
Nov 12 at 10:05














it's the image that came from the url in the query
– Em44
Nov 12 at 10:07




it's the image that came from the url in the query
– Em44
Nov 12 at 10:07












That doesn't clear it up for me, what is an example value of item.Photo? A src attribute must be a url.
– Crowcoder
Nov 12 at 10:11




That doesn't clear it up for me, what is an example value of item.Photo? A src attribute must be a url.
– Crowcoder
Nov 12 at 10:11












Photo is a byte
– Em44
Nov 12 at 10:14




Photo is a byte
– Em44
Nov 12 at 10:14












That doesn't work because src is a url, not a byte array.
– Crowcoder
Nov 12 at 10:16




That doesn't work because src is a url, not a byte array.
– Crowcoder
Nov 12 at 10:16












1 Answer
1






active

oldest

votes

















up vote
0
down vote













If you are storing in encoded format, the create imageHandler.ashx which return image in response and then display to image tag.



Your image tab should contains below



 "~/imageHandler.ashx?id=" + id.ToString();


Handler code



context.Response.ContentType = "image";

using (System.IO.MemoryStream str = new System.IO.MemoryStream(objData.ToArray(), true))
{
str.Write(objData.ToArray(), 0, objData.ToArray().Length);
Byte bytes = str.ToArray();
context.Response.BinaryWrite(bytes);
}


If you are storing url then directly bind image url attribute






share|improve this answer





















  • Since OP is using MVC maybe it would be better to show a Controller instead of ashx.
    – Crowcoder
    Nov 12 at 10:23










  • Thank you fixed it,the problem wasnt with the byte array converter but some other html errors not related to the current post.
    – Em44
    Nov 12 at 10:39











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53259801%2fimage-display-in-asp-net-from-sql%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













If you are storing in encoded format, the create imageHandler.ashx which return image in response and then display to image tag.



Your image tab should contains below



 "~/imageHandler.ashx?id=" + id.ToString();


Handler code



context.Response.ContentType = "image";

using (System.IO.MemoryStream str = new System.IO.MemoryStream(objData.ToArray(), true))
{
str.Write(objData.ToArray(), 0, objData.ToArray().Length);
Byte bytes = str.ToArray();
context.Response.BinaryWrite(bytes);
}


If you are storing url then directly bind image url attribute






share|improve this answer





















  • Since OP is using MVC maybe it would be better to show a Controller instead of ashx.
    – Crowcoder
    Nov 12 at 10:23










  • Thank you fixed it,the problem wasnt with the byte array converter but some other html errors not related to the current post.
    – Em44
    Nov 12 at 10:39















up vote
0
down vote













If you are storing in encoded format, the create imageHandler.ashx which return image in response and then display to image tag.



Your image tab should contains below



 "~/imageHandler.ashx?id=" + id.ToString();


Handler code



context.Response.ContentType = "image";

using (System.IO.MemoryStream str = new System.IO.MemoryStream(objData.ToArray(), true))
{
str.Write(objData.ToArray(), 0, objData.ToArray().Length);
Byte bytes = str.ToArray();
context.Response.BinaryWrite(bytes);
}


If you are storing url then directly bind image url attribute






share|improve this answer





















  • Since OP is using MVC maybe it would be better to show a Controller instead of ashx.
    – Crowcoder
    Nov 12 at 10:23










  • Thank you fixed it,the problem wasnt with the byte array converter but some other html errors not related to the current post.
    – Em44
    Nov 12 at 10:39













up vote
0
down vote










up vote
0
down vote









If you are storing in encoded format, the create imageHandler.ashx which return image in response and then display to image tag.



Your image tab should contains below



 "~/imageHandler.ashx?id=" + id.ToString();


Handler code



context.Response.ContentType = "image";

using (System.IO.MemoryStream str = new System.IO.MemoryStream(objData.ToArray(), true))
{
str.Write(objData.ToArray(), 0, objData.ToArray().Length);
Byte bytes = str.ToArray();
context.Response.BinaryWrite(bytes);
}


If you are storing url then directly bind image url attribute






share|improve this answer












If you are storing in encoded format, the create imageHandler.ashx which return image in response and then display to image tag.



Your image tab should contains below



 "~/imageHandler.ashx?id=" + id.ToString();


Handler code



context.Response.ContentType = "image";

using (System.IO.MemoryStream str = new System.IO.MemoryStream(objData.ToArray(), true))
{
str.Write(objData.ToArray(), 0, objData.ToArray().Length);
Byte bytes = str.ToArray();
context.Response.BinaryWrite(bytes);
}


If you are storing url then directly bind image url attribute







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 at 10:16









Nakul

1089




1089












  • Since OP is using MVC maybe it would be better to show a Controller instead of ashx.
    – Crowcoder
    Nov 12 at 10:23










  • Thank you fixed it,the problem wasnt with the byte array converter but some other html errors not related to the current post.
    – Em44
    Nov 12 at 10:39


















  • Since OP is using MVC maybe it would be better to show a Controller instead of ashx.
    – Crowcoder
    Nov 12 at 10:23










  • Thank you fixed it,the problem wasnt with the byte array converter but some other html errors not related to the current post.
    – Em44
    Nov 12 at 10:39
















Since OP is using MVC maybe it would be better to show a Controller instead of ashx.
– Crowcoder
Nov 12 at 10:23




Since OP is using MVC maybe it would be better to show a Controller instead of ashx.
– Crowcoder
Nov 12 at 10:23












Thank you fixed it,the problem wasnt with the byte array converter but some other html errors not related to the current post.
– Em44
Nov 12 at 10:39




Thank you fixed it,the problem wasnt with the byte array converter but some other html errors not related to the current post.
– Em44
Nov 12 at 10:39


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53259801%2fimage-display-in-asp-net-from-sql%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python