getElementById()。值返回null asp.net MVC
我是ASP.NET MVC的新手,我正在尝试为图表创建过滤器。我已经使用了几个按钮。
@using Common
@model DateModel
<div>
<canvas id="myChart"></canvas>
</div>
<div>
<p>
</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
var dates = [@Html.Raw(Json.Encode(ViewBag.dates))];
var DeletedCount = [@Html.Raw(Json.Encode(ViewBag.DeletedCount))];
var ApprovedCount = [@Html.Raw(Json.Encode(ViewBag.ApprovedCount))];
var ClosedCount = [@Html.Raw(Json.Encode(ViewBag.ClosedCount))];
var OngoingCount = [@Html.Raw(Json.Encode(ViewBag.OngoingCount))];
var NewCount = [@Html.Raw(Json.Encode(ViewBag.NewCount))];
var ToBeAccepetdCount = [@Html.Raw(Json.Encode(ViewBag.ToBeAccepetdCount))];
const data = {
labels: dates[0],
datasets: [{
label: 'Deleted',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: DeletedCount[0],
},
{
label: 'Approved',
backgroundColor: 'rgb(0,192, 0)',
borderColor: 'rgb(0,192, 0)',
data: ApprovedCount[0],
},
{
label: 'Closed',
backgroundColor: 'rgb(128, 128, 128)',
borderColor: 'rgb(128,128, 128)',
data: ClosedCount[0],
},
{
label: 'Ongoing',
backgroundColor: 'rgb(0, 32, 255)',
borderColor: 'rgb(0, 32, 255)',
data: OngoingCount[0],
},
{
label: 'New',
backgroundColor: 'rgb(80, 208, 255)',
borderColor: 'rgb(80, 208, 255)',
data: NewCount[0],
},
{
label: 'To be Accepted',
backgroundColor: 'rgb(90, 255, 128)',
borderColor: 'rgb(90, 255, 128)',
data: ToBeAccepetdCount[0],
},
]
};
const config = {
type: 'line',
data: data,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Tasks'
}
},
scales: {
y: {
beginAtZero: true
,
title: {
display: true,
text: 'Count'
}
}
}
},
};
</script>
<script>
const myChart = new Chart(
document.getElementById('myChart'),
config
);
</script>
<div align="center">
<form method="POST">
<button type="submit" class="btn btn-light" onclick="Today()">Today</button>
<button type="submit" class="btn btn-light">Last 7 Days</button>
<button type="submit" class="btn btn-light">This Month</button>
<button type="submit" class="btn btn-light">Last Month</button>
<script>
function Today() {
document.getElementById('sdate').value = '2022-02-01';
document.getElementById('edate').value = @DateTime.Now.ToString("yyyy-MM-dd");;
console.log(document.getElementById('sdate').value);
console.log(document.getElementById('edate').value);
}
</script>
</form>
</div>
<hr />
<div class="row">
<form method="POST">
<label for="sdatelbl">Start Date</label>
<input type="text" class="form-control" placeholder="@ViewBag.Sdate" id="sdate" name="sdate" value="" size="10" maxlength="10" />
<label for="edatel">End Date</label>
<input type="text" class="form-control" [email protected] id="edate" name="edate" value="" size="15" maxlength="30" />
<br>
<input type="submit" class="btn btn-primary" onclick="" value="Refresh">
</form>
</div>
当我单击此单击时,我想更改 sdata 值另一种用作cutom滤镜的表单。但是,当我单击按钮时,它在控制台中打印正确的值,但在家庭控制器中返回null。
我如何在homecontroller中获得正确的值?
I'm new to asp.net mvc and I'm trying to create filters for my charts.I have useds several buttons for that.
@using Common
@model DateModel
<div>
<canvas id="myChart"></canvas>
</div>
<div>
<p>
</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
var dates = [@Html.Raw(Json.Encode(ViewBag.dates))];
var DeletedCount = [@Html.Raw(Json.Encode(ViewBag.DeletedCount))];
var ApprovedCount = [@Html.Raw(Json.Encode(ViewBag.ApprovedCount))];
var ClosedCount = [@Html.Raw(Json.Encode(ViewBag.ClosedCount))];
var OngoingCount = [@Html.Raw(Json.Encode(ViewBag.OngoingCount))];
var NewCount = [@Html.Raw(Json.Encode(ViewBag.NewCount))];
var ToBeAccepetdCount = [@Html.Raw(Json.Encode(ViewBag.ToBeAccepetdCount))];
const data = {
labels: dates[0],
datasets: [{
label: 'Deleted',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: DeletedCount[0],
},
{
label: 'Approved',
backgroundColor: 'rgb(0,192, 0)',
borderColor: 'rgb(0,192, 0)',
data: ApprovedCount[0],
},
{
label: 'Closed',
backgroundColor: 'rgb(128, 128, 128)',
borderColor: 'rgb(128,128, 128)',
data: ClosedCount[0],
},
{
label: 'Ongoing',
backgroundColor: 'rgb(0, 32, 255)',
borderColor: 'rgb(0, 32, 255)',
data: OngoingCount[0],
},
{
label: 'New',
backgroundColor: 'rgb(80, 208, 255)',
borderColor: 'rgb(80, 208, 255)',
data: NewCount[0],
},
{
label: 'To be Accepted',
backgroundColor: 'rgb(90, 255, 128)',
borderColor: 'rgb(90, 255, 128)',
data: ToBeAccepetdCount[0],
},
]
};
const config = {
type: 'line',
data: data,
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Tasks'
}
},
scales: {
y: {
beginAtZero: true
,
title: {
display: true,
text: 'Count'
}
}
}
},
};
</script>
<script>
const myChart = new Chart(
document.getElementById('myChart'),
config
);
</script>
<div align="center">
<form method="POST">
<button type="submit" class="btn btn-light" onclick="Today()">Today</button>
<button type="submit" class="btn btn-light">Last 7 Days</button>
<button type="submit" class="btn btn-light">This Month</button>
<button type="submit" class="btn btn-light">Last Month</button>
<script>
function Today() {
document.getElementById('sdate').value = '2022-02-01';
document.getElementById('edate').value = @DateTime.Now.ToString("yyyy-MM-dd");;
console.log(document.getElementById('sdate').value);
console.log(document.getElementById('edate').value);
}
</script>
</form>
</div>
<hr />
<div class="row">
<form method="POST">
<label for="sdatelbl">Start Date</label>
<input type="text" class="form-control" placeholder="@ViewBag.Sdate" id="sdate" name="sdate" value="" size="10" maxlength="10" />
<label for="edatel">End Date</label>
<input type="text" class="form-control" [email protected] id="edate" name="edate" value="" size="15" maxlength="30" />
<br>
<input type="submit" class="btn btn-primary" onclick="" value="Refresh">
</form>
</div>
When I click this I want to change sdata value in another form which is used as the cutom filter.But When I click the button it print the correct value in console,But returns null in home controller.
console output
Homecontroller Index
How can I get the correct value in homecontroller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论