【问题标题】:How to update value progress bar bootstrap from controller in ASP .NET Core如何从 ASP .NET Core 中的控制器更新值进度条引导程序
【发布时间】:2021-06-08 06:33:11
【问题描述】:

我有一个表格,用于接收我的用户的电子邮件以获取时事通讯。我在我的仪表板上用计数显示它。但现在我想显示在进度条上及其上个月的百分比 我该怎么办 ?我创建了另一个视图模型来显示某些事物的数量 我可以显示它们的数量,但我也需要在进度条上显示。

我的视图模型:

       public class NewsLetterViewModel
            {
           
                public string Phone { get; set; }
        
           
                public string Email { get; set; }
         
                public DateTime CreateDate { get; set; }
            }

【问题讨论】:

    标签: asp.net-core-mvc viewmodel progress


    【解决方案1】:

    您可以尝试使用 ViewBag 来传递计数和百分比。这是一个演示:

    行动:

    public IActionResult News()
        {
            ViewBag.Count = 0;
            ViewBag.Percentage = 0;
            return View();
        }
        [HttpPost]
        public IActionResult News(NewsLetterViewModel n,int Count)
        {
            //you can pass the count and percentage with ViewBag here
            ViewBag.Count= Count+ 1;
            ViewBag.Percentage=25;
            return View();
        }
    

    查看:

     <div>
        Count:@ViewBag.Count
    </div>
        <div class="progress">
            <div class="progress-bar" role="progressbar" style="width: @ViewBag.Percentage%;" aria-valuenow="@ViewBag.Percentage" aria-valuemin="0" aria-valuemax="100">@ViewBag.Percentage%</div>
        </div>
    <form  method="post">
        <input hidden name="Count" value="@ViewBag.Count" />
        <div class="form-group">
            <label asp-for="Phone" class="control-label"></label>
            <input asp-for="Phone" class="form-control" />
            <span asp-validation-for="Phone" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="Email" class="control-label"></label>
            <input asp-for="Email" class="form-control" />
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
        <div class="form-group">
            <label asp-for="CreateDate" class="control-label"></label>
            <input asp-for="CreateDate" class="form-control" />
            <span asp-validation-for="CreateDate" class="text-danger"></span>
        </div>
        <input type="submit"value="submit" />
    </form>
    

    结果:

    【讨论】:

    • 你用什么工具来制作这样的 gif?
    • 可以在浏览器中搜索录屏转gif,会有很多免费工具。
    猜你喜欢
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 2018-01-18
    • 2018-04-20
    • 2018-07-12
    • 2019-12-29
    • 1970-01-01
    • 2021-11-11
    相关资源
    最近更新 更多