ファイル入力のある非常にシンプルなフォームがあります。フォームを投稿すると、モデルから他の要素を処理できます。ただし、ファイル入力は常に null を返します。ところで、Telerik Sitefinity のビューとコントローラーをカスタム コントロールとして使用します。解決策が見つからなかったため、これに関連している可能性があります。
ここにビューコードがあります
@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;
}
}
また、基本的なフォームタグを付けて投稿するようにしています。お気に入り:
<form method="post" enctype="multipart/form-data"></form>
動いていない。また、Html.BeginForm では、次のようなすべてのバリエーション インデックスとコントローラー名を試しました。
null,null
"Index","ShareRecipeController"
等
最後に、Telerik Sitefinity でのカスタム コントロールの使用に関する情報を提供したいと思います。コントローラーには次の行があります。
[ControllerToolboxItem(Name = "ShareRecipe", Title = "Share Your Recipe", SectionName = "MvcWidgets")]
public class ShareRecipeController : BaseController
誰かが何か考えを持っていれば、それは私たちにとって素晴らしいことです. 前もって感謝します, Serhad.