gpt4 book ai didi

asp.net - 如何在我的 MVC3 模型绑定(bind)中包含 Telerik 文件上传?

转载 作者:行者123 更新时间:2023-12-02 10:50:07 26 4
gpt4 key购买 nike

除了 View 模型参数之外,我不喜欢在 POST 操作方法中使用参数。但是,对于使用 Telerik Upload 帮助程序上传文件,我似乎被迫这样做。发布的值为 IEnumerable<HttpPostedFileBase> 。有什么方法可以将其绑定(bind)到模型,而无需进行自定义模型绑定(bind)。

最佳答案

I don't like to have to use parameters to my POST action methods in addition to my view model parameter.

我也没有。这就是我使用 View 模型的原因:

public class MyViewModel
{
public IEnumerable<HttpPostedFileBase> Files { get; set; }
public string Foo { get; set; }
public string Bar { get; set; }
...
}

然后:

[HttpPost]
public ActionResult Upload(MyViewModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}

if (model.Files != null)
{
foreach (var file in model.Files)
{
if (file != null && file.ContentLength > 0)
{
// process the uploaded file
}
}
}
...
}

关于asp.net - 如何在我的 MVC3 模型绑定(bind)中包含 Telerik 文件上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6635782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com