파일 입력이있는 매우 간단한 형식입니다. 양식을 게시 할 때 모델로부터 다른 요소를 처리 할 수 있습니다. 그러나 파일 입력은 항상 null을 반환합니다. 그런데 Telerik Sitefinity의 뷰 및 컨트롤러를 사용자 정의 컨트롤로 사용합니다. 우리가 아무 해결책도 찾을 수 없기 때문에 이것과 관련이있을 수 있습니다.HttpPostedFileBase를 사용한 파일 입력은 항상 null을 반환합니다.
여기서 도면 부호
@using (Html.BeginForm("Index", null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<div class="form">
<dl>
<dd>
@Html.LabelFor(model => model.ShareRecipe.Name)
@Html.EditorFor(model => model.ShareRecipe.Name)
</dd>
<dd>
@Html.LabelFor(model => model.ShareRecipe.EmailAddress)
@Html.EditorFor(model => model.ShareRecipe.EmailAddress)
</dd>
<dd>
@Html.LabelFor(model => model.ShareRecipe.RecipeArea)
@Html.EditorFor(model => model.ShareRecipe.RecipeArea)
</dd>
<dd>
<input type="file" name="fileUpload" id="fileUpload" />
</dd>
<dd class="last">
<input type="submit" class="btn btn-danger" onclick="return ValidateForm();" value="Send" /></dd>
</dl>
</div>
}
여기 콘트롤러 측이다.
[HttpPost]
public ActionResult Index(ShareRecipeModel model, HttpPostedFileBase fileUpload, FormCollection values)
{
if (fileUpload != null && fileUpload.ContentLength > 0)
{
var fileName = Path.GetFileName(fileUpload.FileName);
var path = Path.Combine(Server.MapPath("~/img/"), fileName);
fileUpload.SaveAs(path);
model.ImageUrl = fileName;
}
}
또한 기본 양식 태그로 게시하려고합니다. like :
<form method="post" enctype="multipart/form-data"></form>
작동하지 않습니다. 나는 우리가이 라인이 Sitefinity Telerik에서 사용자 지정 컨트롤을 사용하는 방법에 대한 정보를 제공하고 싶은 말
null,null
"Index","ShareRecipeController"
등
: 또한 Html.BeginForm 우리는 같은 모든 변화 지수와 컨트롤러 이름을 시도 우리의 컨트롤러 : 사람이 어떤 생각, 사전에 감사합니다, Serhad이있는 경우
[ControllerToolboxItem(Name = "ShareRecipe", Title = "Share Your Recipe", SectionName = "MvcWidgets")]
public class ShareRecipeController : BaseController
그것은 우리에게 좋을 수 있습니다.