草庐IT

Model1Serializer

全部标签

c# - ASP.NET MVC : Views using a model type that is loaded by MEF can't be found by the view engine

我正在尝试创建一个框架,以允许将Controller和View动态导入到MVC应用程序中。到目前为止,它是这样工作的:我正在使用.NET4、ASP.NETMVC3RC和RazorViewEngine每个项目都使用MEF导出和导入Controller-我将给定项目中的一组Controller和View称为“模块”BuildManager使用应用前启动方法和BuildManager.AddReferencedAssembly动态引用使用MEF发现的程序集。使用构建事件将二进制文件(来自导出项目)和View复制到目标项目的文件夹结构中使用自定义Controller工厂选择Controller

c# - OData 和 WebAPI : Navigation property not present on model

我正在尝试使用EntityFramework、WebAPI、OData和Angular客户端组合一个简单的玩具项目。一切正常,除了我在其中一个模型上放置的导航属性似乎不起作用。当我使用$expand调用我的API时,返回的实体没有它们的导航属性。我的类是Dog和Owner,看起来像这样:publicclassDog{//Properties[Key]publicGuidId{get;set;}publicStringName{get;set;}[Required]publicDogBreedBreed{get;set;}publicintAge{get;set;}publicintWe

c# - “模型”与声明“System.Web.Mvc.WebViewPage<TModel>.Model”冲突

我想显示以下客户对象。publicClassCustomer{publiclongId{get;set;}publicstringName{get;set;}publicAddressAddressInfo{get;set;}}publicclassAddress{publicstringDetails{get;set;}publicCityCityInfo{get;set;}publicRegionRegionInfo{get;set;}}并且有一个Controller返回给客户查看publicActionResultGetCustomer(longId){returnView("C

c# - Model 和 ViewModel 的验证最佳实践

我有单独的模型和View模型类。其中viewmodel类仅进行UI级别验证(引用:Validation:ModelorViewModel)。我可以在Controller中验证模型(vewmodel)是否有效。问:如何验证模型(带有数据注释的主要实体)。我没有使用模型对象开发View模型。只需复制属性并添加该特定View中可能需要的所有属性。//ModelClasspublicclassUser{[Required]publicstringEmail{get;set;}[Required]publicDateTimeCreated{get;set;}}//ViewModelClasspu

c# - 处理 ViewModel/Model 中的致命异常

我有一个使用M-V-VM方法编写的应用程序。数据访问在模型中完成。如果此处发生fatalerror(例如,与数据源的连接丢失),则抛出Exception。此异常冒泡到ViewModel。但是,因为数据访问的原始触发器是数据绑定(bind),WPF吞下了这个异常(它只在应用程序在调试器下运行时记录在输出窗口中)。我宁愿这个异常保持未处理状态,这样我的应用程序范围内的未处理异常处理程序就可以拾取它、记录它并优雅地退出。我怎样才能做到这一点? 最佳答案 您可以在调度程序上对异常抛出操作进行排队。//Thispropertyisconnec

c# - MVC3 全局化 : need global filter before model binding

目前,我有一个名为GlobalizationFilter的全局过滤器,它检查路由值、cookie和浏览器语言header以确定请求的正确文化设置:publicoverridevoidOnActionExecuting(ActionExecutingContextfilterContext){//determinecultureInfoThread.CurrentThread.CurrentCulture=cultureInfo;Thread.CurrentThread.CurrentUICulture=cultureInfo;}一切正常,但模型绑定(bind)过程似乎发生在全局过滤器之

c# - 具有内部属性的 JSON Serializer 对象

我有一些内部属性的类,我也想将它们序列化为json。我怎样才能做到这一点?例如publicclassFoo{internalintnum1{get;set;}internaldoublenum2{get;set;}publicstringDescription{get;set;}publicoverridestringToString(){if(!string.IsNullOrEmpty(Description))returnDescription;returnbase.ToString();}}使用保存Foof=newFoo();f.Description="FooExample";

c# - DropCreateDatabaseIfModelChanges EF6 导致 System.InvalidOperationException : The model backing the context has changed

迁移到EntityFramework6后,我在构建服务器上执行单元测试时遇到错误。我正在使用DropCreateDatabaseIfModelChanges初始化程序。当我将其更改为MigrateDatabaseToLatestVersion时一切正常,但我想坚持使用之前的初始化程序。我得到的错误是:System.InvalidOperationException:System.InvalidOperationException:Themodelbackingthe'AppContext'contexthaschangedsincethedatabasewascreated.Consi

c# - 自定义验证属性 : Comparing two properties in the same model

有没有一种方法可以在ASP.NETCore中创建自定义属性,以使用ValidationAttribute验证一个日期属性是否小于模型中的其他日期属性。假设我有这个:publicclassMyViewModel{[Required][CompareDates]publicDateTimeStartDate{get;set;}[Required]publicDateTimeEndDate{get;set;}=DateTime.Parse("3000-01-01");}我正在尝试使用这样的东西:publicclassCompareDates:ValidationAttribute{publi

c# - SignalR 2.0 更改 Json Serializer 以支持派生类型对象

请注意,我在这里明确引用了SignalR2.0...我已经看到一些(令人讨厌的)方法用于SignalR1.1/1.2...但还没有用于2.0。有没有人成功更改SignalR2.0默认json序列化程序以启用派生类型的发送?根据我对SignalR2.0的了解,这应该是可能的,但是,我没有任何运气,也没有在任何地方找到完整的示例。我是这样开始的……如有任何帮助,我们将不胜感激。我的Startup.cs[assembly:OwinStartup(typeof(SignalRChat.Startup))]namespaceSignalRChat{publicclassStartup{publi