【发布时间】:2017-08-16 13:47:18
【问题描述】:
我有一个视图,它在视图呈现时加载一组模块(我们将说其他部分视图)。
所以在主视图中这样想:
<div>
@Html.PartialView("~/Views/MyApp/Partials/Module1.cshtml");
</div>
<div>
@Html.PartialView("~/Views/MyApp/Partials/Module2.cshtml");
</div>
<div>
@Html.PartialView("~/Views/MyApp/Partials/Module3.cshtml");
</div>
部分视图Module2.cshtml 中有一个模型值已更改。实际上,它在 Module2 视图的操作中被更改。我在public ActionResult RenderChecklist(Model pageModel, IGrouping<string, ChecklistItem> list, int checklistCount)中设置模型值:
if (itemCounter == itemCheckedCounter)
{
priorityCounter++;
pageModel.MyAppInfo.ChecklistPriorityLevel = priorityCounter;
listRestrict = "no-restrict";
overlayShow = "hidden";
}
else
{
listRestrict = "no-restrict";
overlayShow = "hidden";
}
根据ChecklistPriorityLevel 的值确定是否在Module1、Module3 等中显示叠加层,但由于Module1 在Module2 之前加载,@987654332 中的ChecklistPriorityLevel 的值@ 总是从 0 开始。
在每个模块中调用的局部视图中的代码是这样的:
@if (moduleRestrict && !(moduleRestrictPriorityLevel <= checklistPriority) && !Model.GetValue<bool>("moduleRestrictBypass"))
{
const string moduleLockMessage = "This section is locked.";
<div class="module overlay show">
<img src="/assets/myapp/images/lock.png" alt="Module Lock">
<p>@moduleLockMessage</p>
</div>
}
模型中的相关代码只是一个常规的get,此时设置:
namespace MyApp.Core.MySite.Models
{
/// <summary>
/// Model for MySite.
/// </summary>
public class MyAppInfoModel
{
... //other models
[Ignore]
public int ChecklistPriorityLevel { get; set; }
}
}
所以我的问题是如何让这个模型的值变化来触发已经加载的其他模块(部分视图)的变化?
免责声明:出于隐私目的,我更改了一些实际代码。我只是想提供足够的信息让观众了解我想要做什么。我正在寻找最佳选择,无论是异步的还是其他方式,以正确获取其他部分视图中的值,而不管哪个部分首先加载。
【问题讨论】:
标签: c# .net asp.net-mvc razor umbraco