【发布时间】:2015-06-13 23:11:07
【问题描述】:
你好我一直在尝试使用部分渲染从主视图访问我的部分视图的视图模型
局部视图是一个对话框,当我点击一个按钮时,对话框被打开,我通过调用控制器来加载它这里是控制器的代码:
public ActionResult ImagesPartial()
{
ViewBag.Images = Directory.EnumerateFiles(Server.MapPath("~/images_upload"))
.Select(fn => "~/images_upload/" + Path.GetFileName(fn));
return PartialView("_ImagesPartial");
}
在我的局部视图中,我使用此代码显示图像和单选按钮
@foreach(var image in (IEnumerable<string>)ViewBag.Images)
{
@Html.RadioButtonFor(model => model.imageVenteCatalog, image)
<img src="@Url.Content(image)" alt="Hejsan" width="100" height="100" class='selectable-image'/>
}
最后在我的主视图中,我使用 renderpartial 来获取选择了哪个单选按钮
@{Html.RenderPartial("_ImagesPartial");}
但是我收到一个错误提示 reference undefined
你知道它可能是什么吗?
编辑:
viewdata[""]没关系,我已经删除了,问题就在这里
@foreach(var image in (IEnumerable)ViewBag.Images)
但是为什么这会导致问题
【问题讨论】:
-
您在代码中维护
ViewData["imageVenteCatalog"]的位置? -
我已经编辑了我的帖子,谢谢
-
我认为你需要
Html.RenderAction以便调用该操作并返回 ``_ImagesPartial` 视图`
标签: c# jquery asp.net asp.net-mvc