【问题标题】:Populate a hidden input to carry to a partial view?填充隐藏输入以携带到局部视图?
【发布时间】:2015-04-18 04:38:07
【问题描述】:

首先,我在 Model.ChatListUsers 的 foreach 中有这个隐藏的输入

<input type="hidden" class="chatId" value="@chat.ChatId"/>

在页面的下方,我正在渲染一个带有引导模式的局部视图。

@Html.Partial("~/Views/Homevestors/Chat/_FlagChatAbuseModal.cshtml", new BusinessEntities.Chat.Chat_Abuse());

我的困境是我需要将从 Model.ChatListUsers 中为正在迭代的特定用户获取的 chatId 传递到引导模式中,以便我可以将消息标记为滥用。我将如何使用 Chat_Abuse 模型填充该模式,以及我在主页上使用的模型中的 chatId,这完全是一个不同的模型。

【问题讨论】:

    标签: c# jquery html model-view-controller


    【解决方案1】:

    您可以为BusinessEntities.Chat.Chat_Abuse 创建一个构造函数重载,并将ChatId 作为参数传入。

    然后渲染部分,你可以使用构造函数重载

    @Html.Partial("~/Views/Homevestors/Chat/_FlagChatAbuseModal.cshtml", new BusinessEntities.Chat.Chat_Abuse(ChatId));
    

    但是,由于您有一个 Chat 集合,如果您需要动态更新模态,最好选择发送 XHR(ajax 调用)以从服务器获取信息并从客户端更新模态。

    【讨论】:

    • 谢谢。我的一位同事过来提出了同样的建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2011-11-16
    相关资源
    最近更新 更多