我怎么可以呈现asp.net MVC 3部分视图 [英] how i can render Partial views in asp.net mvc 3

查看:85
本文介绍了我怎么可以呈现asp.net MVC 3部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ViewData.Model 一些数据,并在我的意见,我想写的局部视图,并通过他们目前的模式我在我的网页。

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.

我怎样才能通过他们的电流 ViewData.Model ,并通过谐音的位置?

How I can pass their current ViewData.Model and render them through the location of partials?

推荐答案

创建您的局部视图是这样的:

Create your partial view something like:

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

然后在您的视图中使用:

Then in your view use:

@Html.Partial("YourPartialViewName", Model)

如果您不想要一个强类型的局部视图从局部视图顶部删除 @model YourModelType ,它会默认为动态键入

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.

更新

默认视图引擎将在同一文件夹中搜索部分的意见,调用部分,然后在〜/查看/共享文件夹的视图。如果您的部分位于不同的文件夹,那么你需要使用的完整路径。不使用〜/

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. Not the use of ~/

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

这篇关于我怎么可以呈现asp.net MVC 3部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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