How to reference controller string in HTML
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to display my controller string in the src of the img tag, but yes I am failing.
Here is my Model code:
public class PigeonDetails
{
[Key]
public int PigeonID { get; set; }
[Required]
[Display(Name = "Ring Number")]
public string RingNumber { get; set; }
[Display(Name = "Pigeon Name")]
public string Name { get; set; }
[Required]
[Display(Name = "Pigeon Color")]
public string Color { get; set; }
[Required]
[Display(Name = "Gender")]
public string Sex { get; set; }
[Required]
[Display(Name = "Year Type")]
public int Year { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
[Display(Name = "Date Added")]
public DateTime DateAdded { get; set; }
public string Image { get; set; }
}
Here is my Controller - Only the method i use:
[HttpGet]
// GET: PigeonDetails/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var pigeonDetails = await _context.PigeonDetails.SingleOrDefaultAsync(m => m.PigeonID == id);
string placeholder = _context.PigeonDetails.Where(u => u.PigeonID == id).Select(u => u.Image).ToString();
pigeonDetails.Image = placeholder;
if (pigeonDetails == null)
{
return NotFound();
}
ViewData["ImagePath"] = pigeonDetails;
return View(pigeonDetails);
}
The pigeonDetails.Image is a string stored in the db (image path - and it stores correctly)
here is my html:
@{var image = (PigeonDetails)ViewData["ImagePath"];}
<img src="@image.Image" id="profile" alt="user" class="img-responsive radius">
It does not display my image on the page, please help.
c# html asp.net-core
|
show 13 more comments
I am trying to display my controller string in the src of the img tag, but yes I am failing.
Here is my Model code:
public class PigeonDetails
{
[Key]
public int PigeonID { get; set; }
[Required]
[Display(Name = "Ring Number")]
public string RingNumber { get; set; }
[Display(Name = "Pigeon Name")]
public string Name { get; set; }
[Required]
[Display(Name = "Pigeon Color")]
public string Color { get; set; }
[Required]
[Display(Name = "Gender")]
public string Sex { get; set; }
[Required]
[Display(Name = "Year Type")]
public int Year { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
[Display(Name = "Date Added")]
public DateTime DateAdded { get; set; }
public string Image { get; set; }
}
Here is my Controller - Only the method i use:
[HttpGet]
// GET: PigeonDetails/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var pigeonDetails = await _context.PigeonDetails.SingleOrDefaultAsync(m => m.PigeonID == id);
string placeholder = _context.PigeonDetails.Where(u => u.PigeonID == id).Select(u => u.Image).ToString();
pigeonDetails.Image = placeholder;
if (pigeonDetails == null)
{
return NotFound();
}
ViewData["ImagePath"] = pigeonDetails;
return View(pigeonDetails);
}
The pigeonDetails.Image is a string stored in the db (image path - and it stores correctly)
here is my html:
@{var image = (PigeonDetails)ViewData["ImagePath"];}
<img src="@image.Image" id="profile" alt="user" class="img-responsive radius">
It does not display my image on the page, please help.
c# html asp.net-core
try to setViewData["ImagePath"] = pigeonDetails;
just before thereturn View(pigeonDetails);
– er-sho
Nov 22 '18 at 11:55
I did, yet no luck .
– stefan van schoor
Nov 22 '18 at 11:59
could you please show your full code of controller
– er-sho
Nov 22 '18 at 12:01
There it is, i edited the post
– stefan van schoor
Nov 22 '18 at 12:06
did u specify any @model on top of view?
– er-sho
Nov 22 '18 at 12:08
|
show 13 more comments
I am trying to display my controller string in the src of the img tag, but yes I am failing.
Here is my Model code:
public class PigeonDetails
{
[Key]
public int PigeonID { get; set; }
[Required]
[Display(Name = "Ring Number")]
public string RingNumber { get; set; }
[Display(Name = "Pigeon Name")]
public string Name { get; set; }
[Required]
[Display(Name = "Pigeon Color")]
public string Color { get; set; }
[Required]
[Display(Name = "Gender")]
public string Sex { get; set; }
[Required]
[Display(Name = "Year Type")]
public int Year { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
[Display(Name = "Date Added")]
public DateTime DateAdded { get; set; }
public string Image { get; set; }
}
Here is my Controller - Only the method i use:
[HttpGet]
// GET: PigeonDetails/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var pigeonDetails = await _context.PigeonDetails.SingleOrDefaultAsync(m => m.PigeonID == id);
string placeholder = _context.PigeonDetails.Where(u => u.PigeonID == id).Select(u => u.Image).ToString();
pigeonDetails.Image = placeholder;
if (pigeonDetails == null)
{
return NotFound();
}
ViewData["ImagePath"] = pigeonDetails;
return View(pigeonDetails);
}
The pigeonDetails.Image is a string stored in the db (image path - and it stores correctly)
here is my html:
@{var image = (PigeonDetails)ViewData["ImagePath"];}
<img src="@image.Image" id="profile" alt="user" class="img-responsive radius">
It does not display my image on the page, please help.
c# html asp.net-core
I am trying to display my controller string in the src of the img tag, but yes I am failing.
Here is my Model code:
public class PigeonDetails
{
[Key]
public int PigeonID { get; set; }
[Required]
[Display(Name = "Ring Number")]
public string RingNumber { get; set; }
[Display(Name = "Pigeon Name")]
public string Name { get; set; }
[Required]
[Display(Name = "Pigeon Color")]
public string Color { get; set; }
[Required]
[Display(Name = "Gender")]
public string Sex { get; set; }
[Required]
[Display(Name = "Year Type")]
public int Year { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
[Display(Name = "Date Added")]
public DateTime DateAdded { get; set; }
public string Image { get; set; }
}
Here is my Controller - Only the method i use:
[HttpGet]
// GET: PigeonDetails/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
var pigeonDetails = await _context.PigeonDetails.SingleOrDefaultAsync(m => m.PigeonID == id);
string placeholder = _context.PigeonDetails.Where(u => u.PigeonID == id).Select(u => u.Image).ToString();
pigeonDetails.Image = placeholder;
if (pigeonDetails == null)
{
return NotFound();
}
ViewData["ImagePath"] = pigeonDetails;
return View(pigeonDetails);
}
The pigeonDetails.Image is a string stored in the db (image path - and it stores correctly)
here is my html:
@{var image = (PigeonDetails)ViewData["ImagePath"];}
<img src="@image.Image" id="profile" alt="user" class="img-responsive radius">
It does not display my image on the page, please help.
c# html asp.net-core
c# html asp.net-core
edited Nov 22 '18 at 12:36
Matt
473416
473416
asked Nov 22 '18 at 11:51
stefan van schoorstefan van schoor
75
75
try to setViewData["ImagePath"] = pigeonDetails;
just before thereturn View(pigeonDetails);
– er-sho
Nov 22 '18 at 11:55
I did, yet no luck .
– stefan van schoor
Nov 22 '18 at 11:59
could you please show your full code of controller
– er-sho
Nov 22 '18 at 12:01
There it is, i edited the post
– stefan van schoor
Nov 22 '18 at 12:06
did u specify any @model on top of view?
– er-sho
Nov 22 '18 at 12:08
|
show 13 more comments
try to setViewData["ImagePath"] = pigeonDetails;
just before thereturn View(pigeonDetails);
– er-sho
Nov 22 '18 at 11:55
I did, yet no luck .
– stefan van schoor
Nov 22 '18 at 11:59
could you please show your full code of controller
– er-sho
Nov 22 '18 at 12:01
There it is, i edited the post
– stefan van schoor
Nov 22 '18 at 12:06
did u specify any @model on top of view?
– er-sho
Nov 22 '18 at 12:08
try to set
ViewData["ImagePath"] = pigeonDetails;
just before the return View(pigeonDetails);
– er-sho
Nov 22 '18 at 11:55
try to set
ViewData["ImagePath"] = pigeonDetails;
just before the return View(pigeonDetails);
– er-sho
Nov 22 '18 at 11:55
I did, yet no luck .
– stefan van schoor
Nov 22 '18 at 11:59
I did, yet no luck .
– stefan van schoor
Nov 22 '18 at 11:59
could you please show your full code of controller
– er-sho
Nov 22 '18 at 12:01
could you please show your full code of controller
– er-sho
Nov 22 '18 at 12:01
There it is, i edited the post
– stefan van schoor
Nov 22 '18 at 12:06
There it is, i edited the post
– stefan van schoor
Nov 22 '18 at 12:06
did u specify any @model on top of view?
– er-sho
Nov 22 '18 at 12:08
did u specify any @model on top of view?
– er-sho
Nov 22 '18 at 12:08
|
show 13 more comments
3 Answers
3
active
oldest
votes
Can you try this
upper page
@model ModelNameSpace.PigeonDetails
and your html element
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius">
Please change namespace. This is just example namespace name ;)
add a comment |
First of all, remove string placeholder
because pigeonDetails already has it if it matches the id. Also there is an issue with .ToString()
on IQueryable as it will return the fully qualified name of the runtime type of the object that received the call.
Second, Remove ViewData bit. You already have Model for your view (better if you use viewmodel instead).
Then add @model PigeonDetails
on top of your view to expose Model property for your view.
Finally, <img src="@Model.Image" />
add a comment |
This is how I would have done it. I removed a lot of unnecessary code.
I trimmed your Edit
action method quite a bit:
[HttpGet]
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
PigeonDetails pigeonDetails = await _context.PigeonDetails
.Where(m => m.PigeonID == id)
.SingleOrDefaultAsync();
if (pigeonDetails == null)
{
return NotFound();
}
return View(pigeonDetails);
}
In your Edit
view page do the following:
@model YourNamespace.PigeonDetails
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius" />
Stay clear of view data, the preferred and safer way is to use a view model.
I hope this helps you.
add a comment |
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%2f53430412%2fhow-to-reference-controller-string-in-html-img-src%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Can you try this
upper page
@model ModelNameSpace.PigeonDetails
and your html element
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius">
Please change namespace. This is just example namespace name ;)
add a comment |
Can you try this
upper page
@model ModelNameSpace.PigeonDetails
and your html element
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius">
Please change namespace. This is just example namespace name ;)
add a comment |
Can you try this
upper page
@model ModelNameSpace.PigeonDetails
and your html element
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius">
Please change namespace. This is just example namespace name ;)
Can you try this
upper page
@model ModelNameSpace.PigeonDetails
and your html element
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius">
Please change namespace. This is just example namespace name ;)
answered Nov 22 '18 at 12:35
Reha BayarReha Bayar
11
11
add a comment |
add a comment |
First of all, remove string placeholder
because pigeonDetails already has it if it matches the id. Also there is an issue with .ToString()
on IQueryable as it will return the fully qualified name of the runtime type of the object that received the call.
Second, Remove ViewData bit. You already have Model for your view (better if you use viewmodel instead).
Then add @model PigeonDetails
on top of your view to expose Model property for your view.
Finally, <img src="@Model.Image" />
add a comment |
First of all, remove string placeholder
because pigeonDetails already has it if it matches the id. Also there is an issue with .ToString()
on IQueryable as it will return the fully qualified name of the runtime type of the object that received the call.
Second, Remove ViewData bit. You already have Model for your view (better if you use viewmodel instead).
Then add @model PigeonDetails
on top of your view to expose Model property for your view.
Finally, <img src="@Model.Image" />
add a comment |
First of all, remove string placeholder
because pigeonDetails already has it if it matches the id. Also there is an issue with .ToString()
on IQueryable as it will return the fully qualified name of the runtime type of the object that received the call.
Second, Remove ViewData bit. You already have Model for your view (better if you use viewmodel instead).
Then add @model PigeonDetails
on top of your view to expose Model property for your view.
Finally, <img src="@Model.Image" />
First of all, remove string placeholder
because pigeonDetails already has it if it matches the id. Also there is an issue with .ToString()
on IQueryable as it will return the fully qualified name of the runtime type of the object that received the call.
Second, Remove ViewData bit. You already have Model for your view (better if you use viewmodel instead).
Then add @model PigeonDetails
on top of your view to expose Model property for your view.
Finally, <img src="@Model.Image" />
edited Nov 22 '18 at 13:00
answered Nov 22 '18 at 12:45
KrishnaDhunganaKrishnaDhungana
1,76431829
1,76431829
add a comment |
add a comment |
This is how I would have done it. I removed a lot of unnecessary code.
I trimmed your Edit
action method quite a bit:
[HttpGet]
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
PigeonDetails pigeonDetails = await _context.PigeonDetails
.Where(m => m.PigeonID == id)
.SingleOrDefaultAsync();
if (pigeonDetails == null)
{
return NotFound();
}
return View(pigeonDetails);
}
In your Edit
view page do the following:
@model YourNamespace.PigeonDetails
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius" />
Stay clear of view data, the preferred and safer way is to use a view model.
I hope this helps you.
add a comment |
This is how I would have done it. I removed a lot of unnecessary code.
I trimmed your Edit
action method quite a bit:
[HttpGet]
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
PigeonDetails pigeonDetails = await _context.PigeonDetails
.Where(m => m.PigeonID == id)
.SingleOrDefaultAsync();
if (pigeonDetails == null)
{
return NotFound();
}
return View(pigeonDetails);
}
In your Edit
view page do the following:
@model YourNamespace.PigeonDetails
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius" />
Stay clear of view data, the preferred and safer way is to use a view model.
I hope this helps you.
add a comment |
This is how I would have done it. I removed a lot of unnecessary code.
I trimmed your Edit
action method quite a bit:
[HttpGet]
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
PigeonDetails pigeonDetails = await _context.PigeonDetails
.Where(m => m.PigeonID == id)
.SingleOrDefaultAsync();
if (pigeonDetails == null)
{
return NotFound();
}
return View(pigeonDetails);
}
In your Edit
view page do the following:
@model YourNamespace.PigeonDetails
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius" />
Stay clear of view data, the preferred and safer way is to use a view model.
I hope this helps you.
This is how I would have done it. I removed a lot of unnecessary code.
I trimmed your Edit
action method quite a bit:
[HttpGet]
public async Task<IActionResult> Edit(int? id)
{
if (id == null)
{
return NotFound();
}
PigeonDetails pigeonDetails = await _context.PigeonDetails
.Where(m => m.PigeonID == id)
.SingleOrDefaultAsync();
if (pigeonDetails == null)
{
return NotFound();
}
return View(pigeonDetails);
}
In your Edit
view page do the following:
@model YourNamespace.PigeonDetails
<img src="@Model.Image" id="profile" alt="user" class="img-responsive radius" />
Stay clear of view data, the preferred and safer way is to use a view model.
I hope this helps you.
edited Nov 22 '18 at 13:14
answered Nov 22 '18 at 13:03
Brendan VogtBrendan Vogt
15.8k29121211
15.8k29121211
add a comment |
add a comment |
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%2f53430412%2fhow-to-reference-controller-string-in-html-img-src%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
try to set
ViewData["ImagePath"] = pigeonDetails;
just before thereturn View(pigeonDetails);
– er-sho
Nov 22 '18 at 11:55
I did, yet no luck .
– stefan van schoor
Nov 22 '18 at 11:59
could you please show your full code of controller
– er-sho
Nov 22 '18 at 12:01
There it is, i edited the post
– stefan van schoor
Nov 22 '18 at 12:06
did u specify any @model on top of view?
– er-sho
Nov 22 '18 at 12:08