html.editorfor 文件,c# - @Html.EditorFor (Image) - Stack Overflow

I am trying to allow a user to upload an image to our website and I'm not quite sure about how to use this. I have tried to use multiple types to define the image, including System.Drawing.Image and HttpPostedFileWrapper but the @Html.EditorFor always (understandably) brings up its attributes as fields to edit.

In my view I did have, instead of @Html.EditorFor I did have but it didn't get taken through to my view as part of the Model? I am quite new to MVC so I am hoping it is something trivial.

Here is my View:

@using (Html.BeginForm()) {

@Html.ValidationSummary(true)

New Image

@Html.LabelFor(model => model.Description)

@Html.EditorFor(model => model.Description)

@Html.ValidationMessageFor(model => model.Description)

@Html.LabelFor(model => model.Image)

}

My Controller:

[HttpPost]

public ActionResult CreateImage(string brand, string collection, ImageEditViewModel imageEditViewModel)

{

string fileName = Guid.NewGuid().ToString();

string serverPath = Server.MapPath("~");

string imagesPath = serverPath + String.Format("Content\\{0}\\Images\\", Helper.Helper.ResolveBrand());

string newLocation = Helper.Helper.SaveImage(fileName, imagesPath, imageEditViewModel.Image.InputStream)

Image image = new Image

{

Collection = ds.Single(c => c.Season == collection

&& c.Brand.Name == brand),

Description = imageEditViewModel.Description,

Location = "newLocation",

Order = Helper.Helper.GetImageOrder(brand, collection)

};

ds.InsertOnSubmit(image);

ds.SubmitChanges();

return RedirectToAction("Brand");

}

And finally the ViewModel:

public class ImageEditViewModel

{

public int CollectionId { get; set; }

public string Description { get; set; }

public HttpPostedFileWrapper Image { get; set; }

public int Order { get; set; }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值