我正在尝试使用Ajax.BeginForm上传图像,但在我的控制器中,文件显示为null。 我的代码是:
@using (Ajax.BeginForm("Create", "PriceManager", new AjaxOptions
{
HttpMethod = "Post",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "PriceList",
OnSuccess = "ClearInputField",
OnFailure = "Fail",
OnComplete = "Complete"
}, new { enctype= "multipart/form-data" }))
我甚至尝试过使用Html.Begin:
@{
var attributes = new Dictionary<string, object>();
attributes.Add("data-ajax-complete ", "Complete");
attributes.Add("data-ajax-mode", "replace");
attributes.Add("data-ajax-update ", "#PriceList");
attributes.Add("id", "form0");
attributes.Add("enctype", "multipart/form-data");
attributes.Add("data-ajax", "true");
}
@using (Html.BeginForm("Create", "ProductManager", FormMethod.Post,attributes))
文件值仍然为空。知道我在这里做错了什么。 感谢
答案 0 :(得分:2)
试试这个:
@using (Ajax.BeginForm("About", "Home", new AjaxOptions
{
HttpMethod = "Post",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "PriceList",
OnSuccess = "ClearInputField",
OnFailure = "Fail",
OnComplete = "Complete"
}, new { enctype = "multipart/form-data" }))
{
<input type="file" name="flResim" />
<input type="submit" value="send" />
}
我尝试过并且工作过。