c# - ASP.NET Core MVC - 在 RenderBody() 中渲染视图
问题描述
_Layout.cshtml
包含RenderBody()
从 处的视图生成内容Index.cshtml
。
Index.cshtml
有一个用 jQuery 加载 jstree 的大型脚本。
$('#tree').jstree({
"plugins": ["search", "wholerow", "dnd", "contextmenu", "massload", "search", "types"],
'core': {
"check_callback": true, // enable all modifications, tweak for rules.
'data': {
'url': function (node) {
return node.id === '#' ? "/Home/GetRoot" : "/Home/GetChildren/" + node.id;
},
'data': function (node) {
return { 'id': node.id };
}
}
}
});
on 事件changed.jstree
捕获有关所选节点的信息。我想在树下呈现一个视图,其中包含一个可编辑的表单,允许在树上执行 CRUD 操作。
$('#tree').on("changed.jstree", function (e, data) {
$.ajax({
type: "GET",
url: "/Home/GetNodeInformation/" + data.selected,
data: '{id: "' + data.selected + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response['node_type'] == 'Portfolio') {
$('#nodeinfo').load('@Url.Action("GetPortfolioDetails", "Portfolio")');
}
console.log(response['node_type'])
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
渲染树和它上面的事件运行良好,我相信这是因为它RenderBody
正在正常运行。
但我打电话的那一刻
$('#nodeinfo').load('@Url.Action("GetPortfolioDetails", "Portfolio")');
整个页面在该 div 中再次呈现。
问题 - 由于我的应用程序是单页应用程序,如何正确管理布局文件中的占位符以处理不同的渲染部分?在这种情况下,我看不到如何渲染树和它下面的详细信息窗格,因为它们是相互关联的。我不认为我可以在这种情况下使用 RenderBody,并且使用 jQuery 动态生成表单将很难维护。
解决方案
推荐阅读
- javascript - Javascript:日期显示不正确(?)值
- java - 通过反射调用变量参数方法
- regex - 在使用正则表达式 SPIP -> WordPress(重定向插件)重定向时需要帮助
- facebook - 无法从 facebook api 获取报告,状态为 400,错误代码为 2601
- javascript - 请从 Exploring ES6 中删除这个示例
- maven - Spring Boot 应用配置文件依赖的数据源
- java - 使用 Retrofit 访问 recyclerview 适配器中的嵌套 JSON 数据
- jquery - fullpage.js 在 reBuild() 之后删除事件侦听器
- javascript - Highstock.js 问题:如何仅针对当天数据绘制 VWAP 指标?
- tensorflow - 同时训练判别器和生成器(Tensorflow)