0
그래서 여러 가이드를 읽었으며 여전히 문제가 있습니다. ASP.NET MVC 4 면도기를 사용하고 있습니다.양식에서 파일을 업로드하는 방법은 무엇입니까?
public class FormsController : Controller
{
[HttpPost]
[ValidateAntiForgeryToken]
[AllowAnonymous]
public ActionResult TechProjectPlan(IEnumerable<HttpPostedFileBase> files, MvcApplication1.Models.TechProjectPlanModel model, string returnUrl)
{
//stuff here
}
}
이 양식은 다른 분야뿐 아니라 많은 파일을 포함
컨트롤러, 그래서 나는 여기뿐만 아니라 모델이 있습니다
는 여기에 지금까지 무슨이다. 요청은 컨트롤러에 도착하고 동작은 정상적으로 이루어 지지만 "파일"은 항상 "Count = 0"이며 비어 있습니다. 여기
는보기 물건 : 당신이 볼 수 있듯이, 입력 유형, 모든 이름 "파일"이 파일을 컨트롤러의 ActionResult의 매개 변수와 일치하고, 내 이해의@using (Html.BeginForm("SubmitForm", "Forms", new { enctype = @"multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<h3>Project Information</h3>
<fieldset>
<legend>Project Information</legend>
<ol style="display:block; *display:inline; *zoom:1;">
<li style="float:left;">
@Html.LabelFor(m => m.Item1)
@Html.TextBoxFor(m => m.Item1, new { @class = "CostItem" })
</li>
<li style="float:left;">
@Html.LabelFor(m => m.Quantity1)
@Html.TextBoxFor(m => m.Quantity1, new { @class = "CostQuantity" })
<span> $</span>
</li>
<li style="float:left;">
@Html.LabelFor(m => m.PerUnitCost1)
@Html.TextBoxFor(m => m.PerUnitCost1, new { @class = "CostPerUnitCost" })
<span> $</span>
</li>
<li style="float:left;">
@Html.LabelFor(m => m.Extension1)
@Html.TextBoxFor(m => m.Extension1, new { @class = "CostExtension" })
</li>
<li style="float:left;">
@Html.LabelFor(m => m.Attachment1)
<input type="file" value="Upload" name="file" id="upload1" style="padding: 5px;" />
</li>
</ol>
<ol style="display:block; *display:inline; *zoom:1;">
<li style="float:left;">
@Html.TextBoxFor(m => m.Item2, new { @class = "CostItem" })
</li>
<li style="float:left;">
@Html.TextBoxFor(m => m.Quantity2, new { @class = "CostQuantity" })
<span> $</span>
</li>
<li style="float:left;">
@Html.TextBoxFor(m => m.PerUnitCost2, new { @class = "CostPerUnitCost" })
<span> $</span>
</li>
<li style="float:left;">
@Html.TextBoxFor(m => m.Extension2, new { @class = "CostExtension" })
</li>
<li style="float:left;">
<input type="file" value="Upload" name="files" id="upload2" style="padding: 5px;" />
</li>
</ol>
</fieldset>
<input type="submit" value="Submit"/>
}
그 컴파일러 암시 적으로 이들과 일치해야합니다.
도움 주셔서 감사합니다.
좋아요. 그래서 파일의 종류가 생깁니다. 이제는 열거 가능 파일에 올바른 수의 파일을 표시하지만 열거 형의 각 파일은 null입니다. 나는 페이지 소스를 살펴보면 Html.BeginForm이 다음과 같이 출력되고 있음을 발견했다.
좋아, 내가 해낸 것은 BeginForm의 FormMethod 매개 변수에서 제외 되었기 때문에 별난 일을하고 있었다. 도와 주셔서 감사합니다! – Tevis