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

前端 未结 7 1257
日久生厌
日久生厌 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:41

    I was playing around with C# code an I accidentally found the solution to your problem haha

    This is the code for the Principal view:

    `@model dynamic 
     @Html.Partial("_Partial", Model as IDictionary)`
    

    Then in the Partial view:

    `@model dynamic 
     @if (Model != null) { 
       foreach (var item in Model) 
       { 
        
    @item.text
    } }`

    It worked for me, I hope this will help you too!!

提交回复
热议问题