最终发展成为一个后端的几个项目 现在我在ASP.NEt深化发展的Web应用程序MVC 3图片目录和对话框控制
我有一个包含一些字段的窗体并可以上传一个完美的图像
我想现在给用户从目录中选择图像的可能性,所以我决定使用一个对话框,一旦点击一个按钮并选择一个图像,我已经能够显示一些图像的对话框,但无法找到如何选择图像并将其绑定到我的视图模型
下面是我在现在
public class PopupController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult ProductPartial()
{
ViewBag.Images = Directory.EnumerateFiles(Server.MapPath("~/images_upload"))
.Select(fn => "~/images_upload/" + Path.GetFileName(fn));
return PartialView("_ProductPartial");
}
}
和意见
<script type="text/javascript" >
$(function() {
$('#dialog').dialog({
autoOpen: false,
width: screen.width/2,
height:screen.height/2,
resizable: false,
title: 'Product',
modal: true,
open: function(event, ui) {
$(this).load("@Url.Action("ProductPartial", "Popup")");
},
buttons: {
"Close": function() {
$(this).dialog("close");
}
}
});
$("#opener").click(function() {
$("#dialog").dialog("open");
});
});
最后的局部视图
@foreach(var image in (IEnumerable<string>)ViewBag.Images)
{
<img src="@Url.Content(image)" alt="Hejsan" width="100" height="100" />
}
我的视图模型包含此属性的代码
public HttpPostedFileBase imageVente { get; set; }
感谢
感谢您的答案,它看起来合法,我使用两个选项,其实,服务器端图像和用户上传,我需要一个其他属性呢?现在我将HttpPostFileBase转换为字节,然后将其保存到我的数据库中 – Coder1409
在澄清后添加了编辑。 –