我有一个名为model的名为PostID的model和另一个名为post的model。在列表view中,当用户单击一个帖子向其添加图像时,它通过一个HtmlActionLink传递这个PostID。
@Html.ActionLink("Add Images", "AddImages", new { id = item.PostID })
它工作得很好,但是我也需要将这个PostId保存在图像Model中。
public ActionResult AddImages(int id)
{
ImageViewModel images = new ImageViewModel();
images.PostID = id;
return View(images);
}
[HttpPost]
public ActionResult AddImages(ImageViewModel image, HttpPostedFileBase images)
{
Image newImage = new Image();
newImage.PostID = image.PostID;
return View("Index");
}这样它就不能工作,当它保存时,PostID的值是0。我也尝试过使用ViewBag,但到目前为止没有任何进展。在AddImages View中,没有针对PostID属性的TextBoxFor或任何东西,因为它不会被用户设置或看到。
发布于 2016-06-19 16:15:44
为了在PostID操作中获得HttpPost,您应该在视图的form标记中添加PostId的输入字段。
@Html.HiddenFor(m=>Model.PostId)https://stackoverflow.com/questions/37909137
复制相似问题