简体   繁体   中英

Populate a hidden input to carry to a partial view?

First off, I have this hidden input within a foreach, of my Model.ChatListUsers

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

And further down the page, I'm rendering a partial view with a bootstrap modal within it.

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

My dilemma is that I need to pass in the chatId that is being grabbed from Model.ChatListUsers for that specific user that is being iterated over, into the bootstrap modal so I can flag the message for abuse. How would I populate that modal with the model of Chat_Abuse, with the chatId from the model I'm using on the main page, which is a different model entirely.

You can create a constructor overload for BusinessEntities.Chat.Chat_Abuse passing in the ChatId as parameter.

Then to render the partial, you can use that constructor overload

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

However, as you have a collection of Chat, if you need to update the modal dynamically, it would be better choice to send XHRs (ajax calls) to get the information from the server and update the modal from the client side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM