【发布时间】:2013-04-12 16:56:46
【问题描述】:
大家好,我正在尝试上传一个简单的图像,但 HttpPostedFileBase 始终保持为空。这是我的代码,我不知道我做错了什么。
这是我在设计视图中的代码:
<fieldset>
<legend>PictureModel</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.PrivacyTypeID) %>
</div>
<div class="editor-field">
<%: Html.DropDownList("PrivacyTypeID", null, new { name = "PrivacyTypeID", title = "Please select privacy type.", id = "PrivacyTypeID" }) %>
<%: Html.ValidationMessageFor(model => model.PrivacyTypeID) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.File1) %>
</div>
<div class="editor-field">
**<input type="file" name="File1" />**
<%: Html.ValidationMessageFor(model => model.File1) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Description) %>
</div>
这是我控制器中的代码:
public ActionResult AddPicture(Guid id, PictureModel model, HttpPostedFileBase File1) { 尝试 {
if (ModelState.IsValid)
{
try
{
Guid albumid = id;
if (File1 != null)
{
var physicalPath = Path.Combine(Server.MapPath("~/Gallery"), System.IO.Path.GetFileName(File1.FileName));
File1.SaveAs(physicalPath);
PicturesBL pictures = new PicturesBL();
谁能告诉我这是什么问题?
【问题讨论】:
-
忘记显示初始开始表单标签
-
请不要将“ASP.NET MVC”简称为“MVC”。一种是框架,另一种是与语言无关的设计模式。这就像调用 IE - “互联网”
-
stackoverflow.com/questions/41347644/… 这是我的问题,有人吗?
标签: asp.net-mvc file-upload httppostedfilebase