Hi i'm trying to bind image in img tag in mvc .this tag is used in asp.net project like this as shown below in the same way i want to bind image in MVC.
public ActionResult ImageDemo()
{
ViewBag.path = "/files/";ViewBag.session = "FCF.jpg";//this 'session' here is just a name called session, not the Session you think
return View();
}
None
0 Points
2 Posts
Trying to call and bind image in img src tag from server in mvc
Nov 29, 2019 05:23 AM|Mohansarabi|LINK
Hi i'm trying to bind image in img tag in mvc .this tag is used in asp.net project like this as shown below in the same way i want to bind image in MVC.
eg ASP.net
<img alt="User Image" width="80px" height="80px" class="img img-thumbnail" src='<%="http://192.0.1.210/p001.ashx?pf=YY&cid="+Session[CommonConstants.SESSION_USER_ID] %>' />
in mvc I want to pass
@ViewBag.session
as parameter instead ofSession[CommonConstants.SESSION_USER_ID]
like this shown below but not getting output<img alt="User Image" width="80px" height="80px" class="img img-thumbnail" src="@Url.Content("'http://192.0.1.201/p001.ashx?pf=YY&cid='"+ ViewBag.session)"/>
how to achieve it in Mvc any idea would be appreciated.
Contributor
3140 Points
983 Posts
Re: Trying to call and bind image in img src tag from server in mvc
Nov 29, 2019 07:35 AM|Yang Shen|LINK
Hi Mohansarabi,
If you want to use ViewBag then you will need no session in your back code, please refer to ASP.NET MVC - ViewBag for more information.
Also, please check below demo:
cshtml:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>ImageDemo</title> </head> <body> <div> <img alt="User Image" width="80" height="80" class="img img-thumbnail" src='@ViewBag.path@ViewBag.session' /> </div> </body> </html>
controller:
Below is the result:
Best Regard,
Yang Shen