Render partial view with dynamic model in Razor view engine and ASP.NET MVC 3

前端 未结 7 1253
日久生厌
日久生厌 2020-12-05 09:28

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

@model dynamic

by using the following code:

@{Html.Re         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 09:48

    Instead of casting the model in the RenderPartial call, and since you're using razor, you can modify the first line in your view from

    @model dynamic
    

    to

    @model YourNamespace.YourModelType
    

    This has the advantage of working on every @Html.Partial call you have in the view, and also gives you intellisense for the properties.

提交回复
热议问题