我仍然不太了解如何使用从另一个 cshtml 文件获取的一个 cshtml 文件中的信息。我的程序由一个画廊组成。当用户单击其中一张图片时,我想重定向到显示图片和与该图片有关的信息的另一个视图,而不是简单地指向仅包含图像 url 的页面。这是我错误尝试的相关代码:
控制器:
public class HomeController : Controller
{
public ActionResult Index()
{
var client = new WebClient();
var response = client.DownloadString(Url.Action("gallery", "photo", null, Request.Url.Scheme));
var jss = new JavaScriptSerializer();
var result = jss.Deserialize<List<Photo>>(response);
return View();
}
public ActionResult FullImage(Photo m)
{
return View();
}
}
看法:
@section mainContent {
<ul class="thumbnails">
@foreach (var photo in Model)
{
<li class="item">
<a href='@Url.Action("FullImage", "Home", new {imageUrl="~/photos/" + photo.FileName, title= photo.Title, description= photo.Description})'>
<img alt="@photo.Description" src="@Url.Content("~/photos/" + photo.FileName)" class="thumbnail-border" width="180" />
</a>
<span class="image-overlay">@photo.Title</span>
</li>
}
</ul>
}
模型:
namespace PhotoGallery.Models
{
public class Photo
{
public string Title { get; set; }
public string FileName { get; set; }
public string Description { get; set; }
public string imageUrl { get; set; }
}
}