图像源中的语法错误 [英] syntax error in image source
本文介绍了图像源中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里有任何语法问题。我已经看到了@ item.FileName的值。它是相同的
作为m images文件夹中的图像名称。当我试图硬编码它是工作。是否有
任何语法错误?图像位于解决方案的图像文件夹中
**查看代码**
is there any syntax issue here.I have seen the value of @item.FileName .It is the same
as the name of image in m images folder. When i tried to hard code it is working.Is there
any syntax error? The image is in image folder of the solution
**Code from View**
@foreach (var item in Model)
{
var x = @item.FileName;
<img src= " @Url.Content("~/Content/themes/base/images/@item.FileName") " />
}
**控制器操作方法**
**Controller Action Method**
public ActionResult Index()
{
SelectionModel sel = new SelectionModel();
List<SelectionModel> lissel = new List<SelectionModel>();
byte[] imagedata;
//byte[] stream ;
string sql = "select filename from filestore";
OracleConnection con = new OracleConnection(ConStr);
OracleCommand com = new OracleCommand(sql, con);
try
{
con.Open(); //Opening a connection
OracleDataReader dr;
dr = com.ExecuteReader();
while (dr.Read())
{
sel.FileName = dr[0].ToString(); //Here i am getting filename from the database
lissel.Add(sel);
}
}
catch (Exception ex)
{
}
return View(lissel);
}
推荐答案
尝试更改控制器操作方法
try by making change in your controller action method
public ActionResult Index()
{
SelectionModel sel = new SelectionModel();
List<SelectionModel> lissel = new List<SelectionModel>();
byte[] imagedata;
//byte[] stream ;
string sql = "select filename from filestore";
OracleConnection con = new OracleConnection(ConStr);
OracleCommand com = new OracleCommand(sql, con);
try
{
con.Open(); //Opening a connection
OracleDataReader dr;
dr = com.ExecuteReader();
while (dr.Read())
{
sel.FileName = "~/Content/themes/base/images/"+dr[0].ToString(); //Here i am getting filename from the database
lissel.Add(sel);
}
}
catch (Exception ex)
{
}
return View(lissel);
}
并且在视图中稍作改动
And make little bit change in view as
@foreach (var item in Model)
{
<img src="@item.FileName" />
}
我找到了解决方案。我不知道如何在Url.Content中使用vairable 。解决方案是
< img src =@ Url.Content(〜/内容/主题/基础/图像/+ @ item.FileName)/>
I have found the solution .I didnt know how to use a vairable in Url.Content.The solution is
<img src= " @Url.Content("~/Content/themes/base/images/" + @item.FileName ) "/>
这篇关于图像源中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文