asp.net-mvc – 当model是父模型上的属性且为null时,强类型局部
发布时间:2020-12-16 06:57:02 所属栏目:asp.Net 来源:网络整理
导读:我在调用 Html.RenderPartial时收到以下异常: The model item passed into the dictionary is of type ‘ChildClass’ but this dictionary requires a model item of type ‘ParentClass’. 这两个类与此相关: public class ChildClass { /* properties *
我在调用
Html.RenderPartial时收到以下异常:
这两个类与此相关: public class ChildClass { /* properties */ } public class ParentClass { public ChildClass ChildProperty { get; set; } /* other properties */ } 我有一个ParentClass实例,其中ChildProperty的值为null. 我有两个部分视图,ParentView(ViewUserControl< ParentClass>)和ChildView(ViewUserControl< ChildClass>). 在第一个视图中,我有以下… <% Html.RenderPartial("~/Views/Controls/ChildView.ascx",Model.ChildProperty); %> 这是抛出此帖子顶部列出的异常的行. 如果ChildProperty不为null,我已验证了正确的功能.为什么MVC认为此属性的空值是父类型? 我可以通过添加仅在ChildProperty不为null的情况下呈现ChildView的代码来解决此问题,但是这一半使得查看失败了. 解决方法
看看这里的答案:
renderpartial with null model gets passed the wrong type
如果有效,您的修复应如下所示: <% Html.RenderPartial("~/Views/Controls/ChildView.ascx",Model.ChildProperty,new ViewDataDictionary()); %> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-core – 如何在.Net Core中将App.config更改为json
- asp.net – 更改后没有应用CSS
- 在IIS托管的asp.net Web应用程序中打开页面时“无法找到资源
- asp.net-mvc – ASP.NET MVC:添加将DisplayName合并到自定
- asp.net-mvc-3 – 在App_code文件夹中使用razor @helper使用
- iis-7 – 捆绑不适用于映射的虚拟目录
- asp.net – 用于.NET的HTML到RTF转换器
- asp.net-mvc-5 – 使用FormsAuthenticationTicket的MVC Ide
- asp.net-mvc – 在ASP.NET MVC ViewModel类中获取数据?
- asp.net-mvc – MVC 4 Ajax.beginform提交 – 导致完全回发
推荐文章
站长推荐
- asp.net – 有谁知道Razor,Spark和NVelocity视图
- asp.net core 2.0 Microsoft.Extensions.Logging
- asp.net – 限制可以输入’textarea’的文本数量
- asp.net-mvc – 使用Html.BeginForm与querystrin
- asp.net – Azure网站上HTTP 1.0代理请求的gzip压
- asp.net – 使用ViewComponent的Ajax
- asp.net – 将非www重定向到www规则导致文件问题
- asp.net-mvc – 如何使用Ninject注入Identity类?
- asp.net – 类库中的dotnet5.4和net451是什么?
- asp.net – .Net平台有Django还是Rails?
热点阅读