Javascript 在jquery进度条中设置模型值
我试图在MVC4Web应用程序中为多个进度条插入一个动态值。 我希望根据模型中的一个数字设置该值,然后为该值的每个实例设置一个单独的进度条 目前,我无法将progress_no的模型值输入javascript,progressbar的代码仅显示第一个进度编号实例 我使用的视图如下所示Javascript 在jquery进度条中设置模型值,javascript,jquery,asp.net-mvc,razor,Javascript,Jquery,Asp.net Mvc,Razor,我试图在MVC4Web应用程序中为多个进度条插入一个动态值。 我希望根据模型中的一个数字设置该值,然后为该值的每个实例设置一个单独的进度条 目前,我无法将progress_no的模型值输入javascript,progressbar的代码仅显示第一个进度编号实例 我使用的视图如下所示 @model IEnumerable<Piggie.Models.Fund> @{ ViewBag.Title = "Funds Summary"; } <hgroup class="
@model IEnumerable<Piggie.Models.Fund>
@{
ViewBag.Title = "Funds Summary";
}
<hgroup class="title">
<h1>@ViewBag.Title</h1>
</hgroup>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.GoalAmount)
</th>
<th>
@Html.DisplayNameFor(model => model.BalanceAmount)
</th>
<th>
@Html.DisplayNameFor(model => model.ReleaseOn)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.GoalAmount)
</td>
<td>
<p id="progressbar">
</p>
</td>
<td>
@Html.DisplayFor(modelItem => item.ReleaseOn)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id })
@Html.ActionLink("Details", "Details", new { id=item.Id })
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
@section Scripts{
@Scripts.Render("~/bundles/jqueryval")
<script>
$(function() {
$( "#progressbar" ).progressbar({
value: @Html.DisplayFor(model => model.progress_no)
});
});
</script>
}
@model IEnumerable
@{
ViewBag.Title=“资金汇总”;
}
@视图包。标题
@ActionLink(“新建”、“创建”)
@DisplayNameFor(model=>model.Name)
@DisplayNameFor(model=>model.GoalAmount)
@Html.DisplayNameFor(model=>model.BalanceAmount)
@DisplayNameFor(model=>model.ReleaseOn)
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.Name)
@DisplayFor(modelItem=>item.GoalAmount)
@DisplayFor(modelItem=>item.ReleaseOn)
@ActionLink(“编辑”,“编辑”,新的{id=item.id})
@ActionLink(“详细信息”,“详细信息”,新的{id=item.id})
@ActionLink(“删除”,“删除”,新的{id=item.id})
}
@节脚本{
@Scripts.Render(“~/bundles/jqueryval”)
$(函数(){
$(“#progressbar”).progressbar({
值:@Html.DisplayFor(model=>model.progress\u no)
});
});
}
我不确定下面java脚本中的值的正确实现方式,但假设如果我能正确实现,那么将为progress\u no字段的每个实例创建一个单独的进度条。这是否正确
编辑:我认为我真正想要解决的问题是如何获取存储在数据库中的变量号,并在javascript中使用它来创建大量的变量进度条
<script>
$(function() {
$( "#progressbar" ).progressbar({
value: @*what goes here *@
});
});
</script>
$(函数(){
$(“#progressbar”).progressbar({
值:@*这里是什么*@
});
});
什么数据类型是进度\u否
?可以显示生成的JavaScript吗?页面上是否有错误?foreach中的id=progressbar?设置id=“progressBar”+Item.id不是“更好”吗?然后你可以做一些“可怕的”事情,为每个项目设置一个hiddenTextbox,然后选择客户端…Progress\u no是int类型。它是一个派生的数字,永远不会超过100。jquery站点上的默认数字是37,因此我希望创建一个百分比数字作为该值。编译时没有错误。当我将脚本标记中的进度值设置为一个数字时,我会得到一个该值的进度条。当我尝试更改这个值以获取progress\u no值时,我什么也得不到,但仍然可以编译。当您查看Razor代码生成的JavaScript时,它看起来正确吗?此外,您的@Model
被定义为IEnumerable
。这意味着您的模型将没有进度\u no
字段。。。此外,每个字段不会有进度条,因为您正在按id选择#progressbar
(页面上应该只有一个id为的元素)。我不知道如何查看Razor代码生成的javaScript。从你上面的答案来看,如果我想显示多个不同的进度条,我必须换一种方式。也许用一个局部的?