我正在尝试简单上传图像,但我的控制器中的 HttpPostedFileBase 始终保持为空。
这是页面:
<% using(Html.BeginForm("AddPicture","Album",FormMethod.Post,new{enctype= "multipart/form-data" }))
{ %>
<%: Html.ValidationSummary(true) %>
<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>
Upload Image: <input type="file" name="File1" />
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
这是页面的控制器:
[HttpPost]
public ActionResult AddPicture(Guid id, PictureModel model, HttpPostedFileBase File1)
{
try
{
if (ModelState.IsValid)
{
var file = Request.Files[0];
try
{
Guid albumid = id;
if (File1 != null)
{
......
谁能指导我我有什么问题?我尝试了一切但没有结果