How to let a button disappear after an action and reappear after another action

Viewed 83

i have a code that can allow a button to be visible if some values have been saved to a database or in this case has been bookmarked and becomes visible in the front end if it has been deleted from the database.ie has not been bookmarked

verseModel.Verses = verses;
var bookmarksForCurrentChapter = _context.Bookmarks.Where(x => x.ChapterId == id).ToList();
            foreach (var verse in verses)
            {
                
                foreach (Bookmark bookmark in bookmarksForCurrentChapter)
                {
                    if (bookmark.VerseId == verse.VerseId) 
                    {
                        verse.IsBookmarked = true;
                    }

                }
                
                
            }

This is the code to check for if the values have been bookmarked or saved in the database

@if (!verse.IsBookmarked)
                        {
                            <td>
                                <form asp-action="SaveBookmark" method="post">
                                    <input type="hidden" name="id" value="@verse.VerseId" />
                                    <input type="hidden" name="text" value="@verse.VerseText" />
                                    <input type="hidden" name="chapterid" value="@Model.ChapterId" />
                                    <button class="btn btn-outline-primary btn-sm">Save</button>
                                 </form>
                        </td>

this is the frontend section that makes the button visible when the values are not bookmarked or saved in the database. So my question is that i want to be add a delete button to this page so that if the value is bookmarked or saved in the database it becomes visible while the save button disappears and if the value has been deleted from the database from this page or from the database directly the delete button will disappear whiles the save button will reappear

else
                        {
                             <td>
                        
                                <form asp-action = "DeleteBookmark" >
                                    <input type = "hidden" name= "id" value = "@verse.VerseId"/>
                                    <button class = "btn btn-danger btn-sm">Delete</button>
                                </form>
                          
                             </td>
                        }
 

this is what i attempted to do but the button does not work when clicked and if the values are deleted from the database it does not affect the page at all

0 Answers
Related