是否有可能通过一个局部视图不同的模式比它在视图中使用的模型? [英] Is it possible to pass a partial view a different model than the model used by the view it is in?
本文介绍了是否有可能通过一个局部视图不同的模式比它在视图中使用的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图这样做,但我得到一个错误说,X型号,但却y为传递。
I tried to do it but I get an error saying that model x was expected but y was passed in.
推荐答案
是的。事实上,你可以使用任何类,但它必须匹配的 @model
声明您的部分的看法。
Yes. In fact you can use any class, but it has to match the @model
declaration of your partial view.
局部视图:
@model partialViewModel
<h2>@Model.partialViewModelProperty</h2>
主视图:
@model mainViewModel
<h1>Model.mainViewModelProperty</h1>
@Html.Partial("_PartialView", new partialViewModel()
{
partialViewModelProperty = "A title"
})
这篇关于是否有可能通过一个局部视图不同的模式比它在视图中使用的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文