HttpPostedFileBase的C#MVC派生类为null [英] C# MVC derived class of HttpPostedFileBase is null

查看:113
本文介绍了HttpPostedFileBase的C#MVC派生类为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FineUploader在C#MVC Web应用程序中上传文件.当使用HttpPostedFileBase作为操作方法的参数时,所有这些都可以正常工作:

I am uploading a file in a C# MVC web application using FineUploader. This all works fine when using HttpPostedFileBase as a parameter on the action method:

public TextJsonResult SaveFile(HttpPostedFileBase qqfile)
{
    // do some stuff      
}

但是我想从HttpPostedFileBase派生一个类来覆盖一些基本属性:

But I want to derive a class from HttpPostedFileBase to override some base properties:

public sealed class DerivedHttpPostedFile : HttpPostedFileBase
{
    public override string FileName { get { /* do something different to base() */ }} 
}

并在Controller中使用它

And use this in the Controller

public TextJsonResult SaveFile(DerivedHttpPostedFile qqfile)
{
    // do some stuff      
}

但是在Controller的action方法中使用我的派生类会导致参数为null.我不确定我错在哪里,因为对StackOverflow和Google的广泛搜索已被证明是徒劳的.

But using my derived class in the Controller's action method results in the parameter being null. I'm not sure where I'm gong wrong, as an extensive search of StackOverflow and Google has proved to be fruitless.

谢谢.

推荐答案

我尝试使用模型绑定程序无法正常工作,并不断抛出异常.

I tried with model binder it won't work keeps on throwing exception.

似乎可以通过InstanceOfType进行源代码调试.

Debugging thru the source code it seems it's checking against InstanceOfType.

我已将其发布在forums.asp.net上 http://forums .asp.net/p/1981337/5674551.aspx?C + MVC + derived + class + of + HttpPostedFileBase + is + null

I've posted it at forums.asp.net http://forums.asp.net/p/1981337/5674551.aspx?C+MVC+derived+class+of+HttpPostedFileBase+is+null

让我们看看是否有事情发生.

let's see if something comes up.

:)

这篇关于HttpPostedFileBase的C#MVC派生类为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆