我想将一些部分 View 渲染到主视图中。所以我像这样使用了 Ext.Net.ComponentLoader:
@(
Html.X().Window()
.Title("Items")
.Width(400)
.Height(300)
.Closable(false)
.Resizable(false)
.Layout(LayoutType.Border)
.Items(i=>{
i.Add(new Panel{
ID = "West1",
Title = "West",
Width=200,
Layout = "Accordion",
Region = Region.West,
Loader = Html.X().ComponentLoader()
.Url(Url.Action("WestItems"))
.Mode(LoadMode.Script)
.Params(new { containerId = "West1" })
});
i.Add(new Panel{
ID = "Center1",
Region = Region.Center,
BodyPadding = 10,
Header = false
});
})
)
这里的主视图是使用操作 Controller "WestItems"
调用部分 View ,这对我来说并不好。我想直接调用部分 View 而不使用操作 Controller ,例如使用 Html.Partial("_PartialView", Model)
我也想将模型作为参数发送到部分 View 。有没有办法直接通过ComponentLoader调用Partial View?如何将模型作为参数发送给局部 View ?
最佳答案
我们应该始终调用 Controller 操作,它们将渲染部分 View 。 部分 View 的调用方式如下:
public PartialViewResult _PartialView(string containerId)
{
...
return new PartialViewResult
{
RenderMode = RenderMode.AddTo,
ContainerId = containerId,
Model = yourModel,
WrapByScriptTag = false
};
}
}
关于asp.net-mvc - 通过Ext.Net.ComponentLoader调用PartialView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23999270/