【发布时间】:2019-04-11 04:33:24
【问题描述】:
当我尝试创建新记录而不选择任何文件时,它给了我 从类型“System.String”到类型“System.Web.HttpPostedFileBase”的参数转换失败,因为没有类型转换器可以在这些类型之间进行转换错误。我想创建记录,无论是否从用户中选择文件。 if HttpPostedFileBase[] null 模型状态应该是有效的。我检查了模型中的 HttpPostedFileBase 也没有必需的验证。
[HttpPost]
public ActionResult NewTheme(ThemeModel themeModel, ColorItem colorItem, ImageItem imageItem, Dictionary<string, HttpPostedFileBase[]> selectedImageList)
{
try
{
if (ModelState.IsValid)
{
}
}
}
我希望当 Dictionary HttpPostedFileBase 也变为 null 时 ModelState 也有效
【问题讨论】:
-
我们如何重现这个?
-
@John 问题是模型状态在我不选择文件输入时无效,然后 DIctionary HttpPostedFileBase [] 为空。我希望能够在 httppostedfilebase 也为 null 时对有效状态进行建模
-
我们能看到模型吗?
-
你能展示你的模型吗?
-
请分享您发送的请求。
标签: c# asp.net-mvc asp.net-mvc-5