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

邮差的信 提交于 2019-11-27 12:55:09

问题


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 their current ViewData.Model and render them through the location of partials?


回答1:


Create your partial view something like:

@model YourModelType
<div>
  <!-- HTML to render your object -->
</div>

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)



回答2:


<%= Html.Partial("PartialName", Model) %>


来源:https://stackoverflow.com/questions/5441615/how-i-can-render-partial-views-in-asp-net-mvc-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!