MVC PartialViews 模型
MVC PartialViews models
我想为我的部分视图使用不同的模型,该怎么做?你有例子吗?
<div id="tabs">
<ul>
<li><a href="#tabs-1">first tab</a></li>
<li><a href="#tabs-2">second tab</a></li>
<li><a href="#tabs-3">third tab</a></li>
</ul>
<div id="tabs-1">
@{Html.RenderPartial("FirstTabView", Model)}
</div>
<div id="tabs-2">
@{Html.RenderPartial("SecondTabView", Model)}
</div>
<div id="tabs-3">
@{Html.RenderPartial("ThirdTabView", Model)}
</div>
</div>
您可以将子模型作为主模型的一部分,例如:
public class YourModel
{
public FirstTabModel FirstTab { get; set; }
public SecondTabModel SecondTab { get; set; }
public ThirdTabModel ThirdTab { get; set; }
}
那么你可以这样做:
<div id="tabs-1">
@{Html.RenderPartial("FirstTabView", Model.FirstTab)}
</div>
<div id="tabs-2">
@{Html.RenderPartial("SecondTabView", Model.SecondTab)}
</div>
<div id="tabs-3">
@{Html.RenderPartial("ThirdTabView", Model.ThirdTab)}
</div>
我想为我的部分视图使用不同的模型,该怎么做?你有例子吗?
<div id="tabs">
<ul>
<li><a href="#tabs-1">first tab</a></li>
<li><a href="#tabs-2">second tab</a></li>
<li><a href="#tabs-3">third tab</a></li>
</ul>
<div id="tabs-1">
@{Html.RenderPartial("FirstTabView", Model)}
</div>
<div id="tabs-2">
@{Html.RenderPartial("SecondTabView", Model)}
</div>
<div id="tabs-3">
@{Html.RenderPartial("ThirdTabView", Model)}
</div>
</div>
您可以将子模型作为主模型的一部分,例如:
public class YourModel
{
public FirstTabModel FirstTab { get; set; }
public SecondTabModel SecondTab { get; set; }
public ThirdTabModel ThirdTab { get; set; }
}
那么你可以这样做:
<div id="tabs-1">
@{Html.RenderPartial("FirstTabView", Model.FirstTab)}
</div>
<div id="tabs-2">
@{Html.RenderPartial("SecondTabView", Model.SecondTab)}
</div>
<div id="tabs-3">
@{Html.RenderPartial("ThirdTabView", Model.ThirdTab)}
</div>