【发布时间】:2012-06-01 12:33:47
【问题描述】:
我有一个 PartialView 是一个图像上传,基本上我显示一些图像,然后显示正常的上传按钮:-
@model MvcCommons.ViewModels.ImageModel
<table>
@if (Model != null)
{
foreach (var item in Model)
{
<tr>
<td>
<img src= "@Url.Content("/Uploads/" + item.FileName)" />
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
</tr>
}
}
</table>
@using (Html.BeginForm("Save", "File", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<input type="file" name="file" />
<input type="submit" value="submit" /> <br />
<input type="text" name="description" />
}
现在我的想法是把它放在不同的页面中。我已经在 1 页中尝试过并且工作正常,但是当我上传图片时,
public ActionResult ImageUpload()
{
ImageModel model = new ImageModel();
model.Populate();
return View(model);
}
我想回到“上一个”视图,即托管此部分视图的视图?当我像上面那样做return View(model) 时,我会进入我不想看到的ImageUpload 部分视图。
感谢您的帮助和时间。
***更新***** **** 我暂时选择了简单的路线,并硬编码了实际的视图名称
public ActionResult ImageUpload()
{
ImageModel model = new ImageModel();
model.Populate();
return View("~/Views/Project/Create.cshtml", model);
}
但是我得到了一个错误:-
传入字典的模型项的类型为MvcCommons.ViewModels.ImageModel,但此字典需要MvcCommons.Models.Project 类型的模型项。
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-3 c#-4.0 razor partial-views