how i can render Partial views in asp.net mvc 3

前端 未结 2 1943
南旧
南旧 2020-12-14 15:10

I have some data in ViewData.Model, and in my views I want to write a partial view and to pass their current model I have in my page.

How I can pass the

2条回答
  •  情话喂你
    2020-12-14 15:47

    Create your partial view something like:

    @model YourModelType
    

    Then in your view use:

    @Html.Partial("YourPartialViewName", Model)
    

    If you do not want a strongly typed partial view remove the @model YourModelType from the top of the partial view and it will default to a dynamic type.

    Update

    The default view engine will search for partial views in the same folder as the view calling the partial and then in the ~/Views/Shared folder. If your partial is located in a different folder then you need to use the full path. Note the use of ~/ in the path below.

    @Html.Partial("~/Views/Partials/SeachResult.cshtml", Model)
    

提交回复
热议问题