使用asp.net-4.0,我做到了:
slideshow.aspx
<div class="wrapCarousel">
<div class="Carousel">
<% foreach(var image in Images) { %>
<div class="placeImages">
<img width="150px" height="150px" src="../Img/<%=image.TnImg%>" alt="<%=image.Name%>" />
<div class="imageText">
<%=image.Name%>
</div>
</div>
<% } %>
</div>然后图片出现在代码后面,就像这样的slideshow.aspx.cs:
public class Image
{
public string TnImg { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string RefPlace { get; set; }
public string RefInfo { get; set; }
public string RefInfoDynamic { get; set; }
public Image(string TnImg, string Name, string City, string RefPlace, string RefInfo, string RefInfoDynamic)
{
this.TnImg = TnImg;
this.Name = Name;
this.City = City;
this.RefPlace = RefPlace;
this.RefInfo = RefInfo;
this.RefInfoDynamic = RefInfoDynamic;
}
}
Images.Add(new Image("", "", "", "", "", "");现在有了ASP.NETMVC2,我没有任何代码,所以我不能像以前那样访问图片,而是需要把它传递给.aspx文件。
这是怎么做的?
谢谢我
发布于 2010-11-21 21:40:56
您将使用强类型视图,并将模型从控制器传递到视图中。
您可以在here上找到一些详细信息。
然后,您可以使用类似于...
<% foreach(var image in Model.Images) { %>
<div><%= image.Name %></div>
<% } %>你的控制器看起来像下面这样,你可能会从一些外部来源得到一个图像列表。
public ActionResult Index()
{
ImageViewModel imageViewModel = new ImageViewModel();
imageViewModel.Images = _imageRepository.GetImages();
return View ("Index", imageViewModel);
}在上面的代码中,您可以只使用下面的代码来呈现视图
return View (imageViewModel); 我更喜欢显式地使用下面的调用,并指定要呈现的视图的名称(即使它与当前控制器操作的名称相同,但我认为它读起来更好)
return View ("Index", imageViewModel); https://stackoverflow.com/questions/4238076
复制相似问题