大家好,我正在尝试上传一个简单的图像,但 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) { try {
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();
谁能告诉我是什么问题??