public IActionResult OnGetTestPartial()
{
return new PartialViewResult()
{
ViewName = "Test",
ViewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = new TestPartialData { Data = "inputhere" },
}
};
}
文件名“Test.cshtml”中的部分视图与上述类位于同一文件夹中 .
@using YourNamespace
@model TestPartialData
<div>Hello, model value: @Model.Data</div>
2 回答
我想通了 . 它并不像MVC那样直截了当 . 您必须创建一个空的
ViewDataDictionary()
,然后将其Model属性设置为partial的填充模型 .View Model / Handler
我现在可以通过ajax GET调用这个处理程序并让它返回部分's HTML. I can then set the partial' s
div
并按预期部分刷新 .这是我正在制作的AJAX调用:
非常感谢TechFisher搞清楚,这里有一个更清洁的例子 .
文件名“Test.cshtml”中的部分视图与上述类位于同一文件夹中 .
用jquery加载它异步