我在_layout中添加了一個共享的div,顯示了當前的余額(因為我想讓它顯示在網站的所有頁面中)
。現在,金額是硬編碼的,我寫了3000美元。 我怎樣才能從資料庫中獲取這個值? 在_layout頁面上沒有控制器。 我在谷歌上看到使用@Html.Action的選項。 這是不可行的(我只有Html.ActionLink)
。這里是_layout的部分:
<div class="container-fluid" >
<div class=" row">
<h1 class="col-6"> </h1>
<h1 class="col-4 text-center" style="font-size:30px;font-weight:bold;color:forestgreen;border-style:inset" >
<img src="~/Images/Coin.jpg" alt="網站標志" style="height:30px; width: 30px" />
當前余額 : 3000美元
</h1>
</div>
<main role="main" class="pb-3" >
@RenderBody()。
</main>
</div>
CodePudding
編輯:
關于 "Uncaught ReferenceError: $ is not defined at (index) "的錯誤,似乎是JQuery參考沒有添加成功,嘗試在JQuery腳本之前添加JQuery參考:
編輯
關于 "Uncaught ReferenceError: $ is not defined at (index) "的錯誤,似乎是JQuery參考沒有添加成功。
<script src="~/lib/jquery/dist/jquery.min.js"> </script>
<腳本 src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"> </script>
<script>
$(function () {
$.ajax({
型別。"Get"。
網址。"/Home/GetMessage"。
success: function (data) {
//Update the page content.
$('#returndata').html(""); //clear the content
$('#returndata').html(data); //添加最新的資料。.
},
error: function (response) {
console.log(response.responseText)。
}
});
});
</script>
你也可以使用CDN參考:
你也可以使用CDN參考。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script>
_layout.csthml資源如下:
<! DOCTYPE html>
<html lang="en"/span>>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Test</title>
<link rel="styleheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="styleheet" href="~/css/site.css" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3" >
<div class="container">
< a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="index"> 測驗</a>
<按鈕 class="navbar-toggler" type="按鈕" data-toggle="折疊" data-target=" 。 navbar-collapse" aria-controls="navbarSupportedContent"。
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"> </span>
</button>
<div class="navbar-collapse collapse d-sm-line-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1"/span>>
<li class="nav-item"/span>>
< a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="index" > 首頁</a>
</li>
<li class="nav-item">
< a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy"> 隱私</a>
</li>
</ul>
</div>
<div id="txt_navbar_output">
<h4 class="col-4 text-center" style="font-size:16px;font-weight:bold;color:forestgreen;border-style:inset;" /span>>
<img src="~/Images/Coin.jpg" alt="網站標志" style="height:30px; width: 30px" />
當前余額 : <span id="returndata">3000$</span>
</h4>
</div>
</div>
</nav>
</header>
<div class="container"/span>>
<main role="main" class="pb-3" >
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
© 2020 - Test - <a asp-area="" asp-controller="首頁" asp-action="隱私"> Privacy< /a>
</div>
</footer>
<腳本 src="~/lib/jquery/dist/jquery.min.js"> </script>
<腳本 src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<腳本 src="~/js/site.js" asp-append-version="true"> </script>
@RenderSection("Scripts", required: false)
<腳本>
$(function () {
$.ajax({
型別。"Get"。
網址。"/Home/GetMessage"。
success: function (data) {
//Update the page content.
$('#returndata').html(""); //clear the content
$('#returndata').html(data); //添加最新的資料。.
},
error: function (response) {
console.log(response.responseText)。
}
});
});
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/320342.html
標籤:
上一篇:FFMPEGApi從YUV420P轉換到RGB產生奇怪的輸出
下一篇:當欄位為空時,復選框過濾表


