填充隐藏的输入以携带到局部视图?
Populate a hidden input to carry to a partial view?
首先,我在 Model.ChatListUsers
的 foreach 中有这个隐藏输入
<input type="hidden" class="chatId" value="@chat.ChatId"/>
在页面下方,我正在渲染其中包含 bootstrap 模态的部分视图。
@Html.Partial("~/Views/Homevestors/Chat/_FlagChatAbuseModal.cshtml", new BusinessEntities.Chat.Chat_Abuse());
我的困境是我需要将从 Model.ChatListUsers 获取的 chatId 传递给正在迭代的特定用户,并将其传递到 bootstrap 模态中,以便我可以标记消息虐待。我如何使用 Chat_Abuse 的模型填充该模式,以及我在主页上使用的模型中的 chatId,这完全是一个不同的模型。
您可以为 BusinessEntities.Chat.Chat_Abuse
创建构造函数重载,将 ChatId
作为参数传入。
然后要渲染部分,您可以使用该构造函数重载
@Html.Partial("~/Views/Homevestors/Chat/_FlagChatAbuseModal.cshtml", new BusinessEntities.Chat.Chat_Abuse(ChatId));
但是,由于您有一个 Chat 集合,如果您需要动态更新模态,最好选择发送 XHR(ajax 调用)从服务器获取信息并更新来自客户端的模式。
首先,我在 Model.ChatListUsers
的 foreach 中有这个隐藏输入<input type="hidden" class="chatId" value="@chat.ChatId"/>
在页面下方,我正在渲染其中包含 bootstrap 模态的部分视图。
@Html.Partial("~/Views/Homevestors/Chat/_FlagChatAbuseModal.cshtml", new BusinessEntities.Chat.Chat_Abuse());
我的困境是我需要将从 Model.ChatListUsers 获取的 chatId 传递给正在迭代的特定用户,并将其传递到 bootstrap 模态中,以便我可以标记消息虐待。我如何使用 Chat_Abuse 的模型填充该模式,以及我在主页上使用的模型中的 chatId,这完全是一个不同的模型。
您可以为 BusinessEntities.Chat.Chat_Abuse
创建构造函数重载,将 ChatId
作为参数传入。
然后要渲染部分,您可以使用该构造函数重载
@Html.Partial("~/Views/Homevestors/Chat/_FlagChatAbuseModal.cshtml", new BusinessEntities.Chat.Chat_Abuse(ChatId));
但是,由于您有一个 Chat 集合,如果您需要动态更新模态,最好选择发送 XHR(ajax 调用)从服务器获取信息并更新来自客户端的模式。