在 ASP.NET MVC 中上传图像 [英] Uploading image in ASP.NET MVC
问题描述
我有一个上传表单,我想传递我的信息,例如图像和其他一些字段,但我不知道如何上传图像..
这是我的控制器代码:
[HttpPost]公共操作结果创建(tblPortfolio tblportfolio){如果(模型状态.IsValid){db.tblPortfolios.AddObject(tblportfolio);db.SaveChanges();return RedirectToAction("索引");}返回视图(tblportfolio);}
这是我的视图代码:
@model MyApp.Models.tblPortfolio<h2>创建</h2>@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })){@Html.ValidationSummary(true)<字段集><legend>tblPortfolio</legend><div class="editor-label">@Html.LabelFor(model => model.Title)
<div class="editor-field">@Html.EditorFor(model => model.Title)@Html.ValidationMessageFor(model =>model.Title)
<div class="editor-label">@Html.LabelFor(model => model.ImageFile)
<div class="editor-field">@Html.TextBoxFor(model => model.ImageFile, new { type = "file" })@Html.ValidationMessageFor(model =>model.ImageFile)