【发布时间】:2017-10-22 04:17:35
【问题描述】:
我正在尝试加载选项卡内部的部分视图,但它没有显示数据。
我正在使用以下代码,我可以不只是使用剃刀代码做一个循环吗?这是在我希望从另一个视图加载的部分视图中
@model IEnumerable<solitude.models.ProductImages>
@{
ViewData["Title"] = "ProductPicturesList";
Layout = "~/Views/Shared/_LoginAdminLte.cshtml";
}
<h2>ProductPicturesList</h2>
<table class="table">
<thead>
<tr>
<th>
Picture Title
</th>
<th>
Image
</th>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
</tr>
<td>
<a asp-action="Edit" asp-route-id="@item.ProductID">Edit</a> |
<a asp-action="Details" asp-route-id="@item.ProductID">Details</a> |
<a asp-action="Delete" asp-route-id="@item.ProductID">Delete</a>
</td>
}
</tbody>
</table>
它在主列表中的原因我正在使用视图模型,但我想在表单上传上方显示图片列表我最好的方法是什么,因为 obv 它没有返回任何结果我正在使用控制器我的主页。
@model solitude.models.Models.ViewModels.ProductImageVm
@*
For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
@Html.PartialAsync("_ProductPicturesList.cshtml")
<div class="form-group">
<form asp-controller="Products" asp-action="FileUpload" asp-route-returnurl="@ViewData["ReturnUrl"]" enctype="multipart/form-data" method="post" class="form-horizontal" role="form">
<input asp-for="Title" />
<input asp-for="ProductId" type="hidden" />
<input asp-for="Image" />
<input type="submit" />
</form>
编辑 2 我的产品图片作为一个类应该改变
public class ProductImages
{
[Key]
public int ProductImageId { get; set; }
public int ProductID { get; set; }
public string ProductImageTitle { get; set; }
public string ProductImageUploadUrl { get; set; }
public string ProductImageRealPath { get; set; }
public string ServerIpAddress { get; set; }
public string ProductImageAltTag { get; set; }
public int DisplayOrder { get; set; }
public string Image { set; get; }
}
}
【问题讨论】:
-
好吧,您不会将带有
IEnumerable<solitude.models.ProductImages>的模型传递给您的部分。在此处添加它们:@Html.PartialAsync("_ProductPicturesList.cshtml", (model to send to partial view))。
标签: c# asp.net-mvc razor