我正在创建一个MVC4应用程序,当我尝试将一个表单从我的视图恢复到我的控制器时,我遇到了一些麻烦.
我读了几个关于这个主题的SO帖子但不幸的是,我没有设法找到哪个对象没有无参数构造函数.我的所有模型类都有一个无参数构造函数.在调试中,错误堆栈只在Internet Explorer中,但在Visual Studio中没有任何反应.
这是错误堆栈:
异常详细信息:System.MissingMethodException:没有为此对象定义的无参数构造函数.
来源错误:
在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
堆栈跟踪:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +117
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +247
System.Activator.CreateInstance(Type type, Boolean nonPublic) +106
System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +243
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +151
System.Web.Mvc.DefaultModelBinder.UpdateCollection(ControllerContext controllerContext, ModelBindingContext bindingContext, Type elementType) +545
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +609
System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor …Run Code Online (Sandbox Code Playgroud) 我必须实现一个Microsoft Word文档生成器,其中嵌入了excel图形.我的一个限制是使我生成的docx与Microsoft word 2010和2003 +兼容包一起工作.
我没有设法使它适用于他们两个.我可以使它适用于Word 2010,但该文档不适用于2003,反之亦然.
经过多次搜索使其适用于Word 2003后,我在我的代码中添加了这个:
private static void Word2003(ChartPart importedChartPart, MainDocumentPart mainDocumentPart, Stream fileStream)
{
var ext = new ExternalData { Id = "rel" + 5 };
importedChartPart.ChartSpace.InsertAt(ext, 3);
var fi = new FileInfo(@"generated.xlsx");
importedChartPart.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/package", new Uri(fi.Name, UriKind.Relative), "rel5");
EmbeddedPackagePart embeddedObjectPart = mainDocumentPart.AddEmbeddedPackagePart(@"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
Stream copyStream = new MemoryStream();
fileStream.CopyTo(copyStream);
embeddedObjectPart.FeedData(copyStream);
}
Run Code Online (Sandbox Code Playgroud)
但此时生成的文档无法与Word 2010一起使用.如果我删除这两个lignes:
var ext = new ExternalData { Id = "rel" + 5 };
importedChartPart.ChartSpace.InsertAt(ext, 3);
Run Code Online (Sandbox Code Playgroud)
从以前的代码,它适用于Word 2010,但不适用于Word 2003.
我尝试了几件事,但我没有设法让它适用于每个案例.
你可以在这里找到这一小段代码
先决条件是Excel文件的模板,其中包含图表和图形.
编辑:生成的文档始终与Microsoft …
我正在做一些事情,我遇到了一个我不明白的问题.
double d = 95.24 / (double)100;
Console.Write(d); //Break point here
Run Code Online (Sandbox Code Playgroud)
控制台输出为0.9524(如预期的那样),但如果我在停止程序后查看"d",则返回0.95239999999999991.
我尝试了每一次演员,结果是一样的.问题是我在其他地方使用'd',这个精度问题使我的程序失败了.
那为什么这样做呢?我该如何解决?