呈现在的Razor视图引擎和ASP.NET MVC 3动态模型的局部视图 [英] Render partial view with dynamic model in Razor view engine and ASP.NET MVC 3

查看:390
本文介绍了呈现在的Razor视图引擎和ASP.NET MVC 3动态模型的局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试呈现的模型类型被指定为一个局部视图:

When I try to render a partial view whose model type is specified as:

@model dynamic

通过使用以下code:

by using the following code:

@{Html.RenderPartial("PartialView", Model.UserProfile);}

我得到了以下异常:

I get the following exception:

'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'RenderPartial' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

然而,在.aspx文件相同的code完美的作品。有什么想法?

However, the same code in a .aspx file works flawlessly. Any thoughts?

推荐答案

刚刚找到了答案,看来我在那里放置的RenderPartial code中的观点有一个动态模型,因此,MVC不可能选择正确的方法使用。铸造模型中的RenderPartial调用正确的类型固定的问题。

Just found the answer, it appears that the view where I was placing the RenderPartial code had a dynamic model, and thus, MVC couldn't choose the correct method to use. Casting the model in the RenderPartial call to the correct type fixed the issue.

来源: http://stackoverflow.com/questions/3822546

这篇关于呈现在的Razor视图引擎和ASP.NET MVC 3动态模型的局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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