ASP.net MVC-视图中的动态引导进度栏

时间:2019-03-20 22:27:10

标签: asp.net-mvc progress-bar

我正在尝试使用Web应用程序中的进度条来直观显示原因(请愿)相对于目标签名数的签名数。原因模型的一部分是另一个表中存在的签名列表。我正在尝试创建当前变量并将其添加到进度条,但是我的尝试似乎都没有奏效,而且我不确定我要去哪里。我尝试了以下代码的几种排列,但均未成功。我只是在网络浏览器中看到空白的进度条。任何帮助将不胜感激:

@model IEnumerable<SoWokeWebApp.Models.Cause.Cause>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@foreach (var item in Model)
{
<div class="jumbotron">
    <img src="@item.ImageURL" alt="Alternate Text" class="img-fluid" />
    <h1>@Html.DisplayFor(model => item.CauseTitle)</h1>
    <p>@Html.DisplayFor(model => item.Description)</p>
    <p>@item.Signatures.Count</p>
    @foreach (var Signature in item.Signatures)
    {
        <p>@Signature.UserEmail</p>
        <p>@Signature.FirstName</p>
    }
    @{int target = item.TargetSignatures;
        int current = item.Signatures.Count;
        int progress = current / target * 100;}
    <div class="progress">
        <div class="progress-bar" role="progressbar" style="width: @progress%" aria-valuenow="@current" aria-valuemin="0" aria-valuemax="@target"></div>
    </div>
    <p><a class="btn btn-primary btn-lg" href="#" role="button">@Html.ActionLink("Sign Cause", "Create", "Signatures")</a></p>
</div>

模型如下:

public class Cause
    {   

        [Key]
        [StringLength(100)]
        [DisplayName("Cause Title")]
        public string CauseTitle { get; set; }
        [Required]
        [StringLength(500)]
        public string Description { get; set; }
        [Required]
        public string UserEmail { get; set; }
        [Required]
        [DisplayName("Date Posted")]
        public DateTime DatePosted { get; set; }
        public string ImageURL { get; set; }
        [DisplayName("Catagory")]
        public string CatagoryTitle { get; set; }
        [ForeignKey("CatagoryTitle")]
        public Catagory Catagory { get; set; }
        [DisplayName("Signatures Target")]
        public int TargetSignatures { get; set; }

        public virtual List<Signature> Signatures { get; set; }
    }

public class Signature
    {
        [Key]
        public int SignatureId { get; set; }
        [Required]
        public string UserEmail { get; set; }
        [Required]
        public string FirstName { get; set; }
        [Required]
        public string LastName { get; set; }
        [Required]
        public string CauseTitle { get; set; }
        [ForeignKey("CauseTitle")]
        public virtual Cause Cause { get; set; }

    }

0 个答案:

没有答案