如何根据今天的日期查看数据?

发布于 2025-02-12 07:12:07 字数 814 浏览 1 评论 0原文

我需要根据今天的日期查看数据

,这是控制器代码:

  public ActionResult Edit(int programId, int hospitalNo  ,DateTime CountDate )
        {
            var stat = _context.STATISTICS.Where(d => d.program_id == programId && d.hospital_no == hospitalNo && d.DATE == CountDate).ToList();
            return View(stat);
           
        }

这是打开视图的按钮:

我创建了会话参数保存登录日期并尝试调用它,但它不起作用:

  Session["LoginDate"] = DateTime.Now.ToShortDateString();

    @Html.ActionLink("Statistics", "Edit","Statistics", new {programId  = item.program_id, hospitalNo = item.hospital_id ,CountDate = Convert.ToDateTime(Session["LoginDate"]) }, new { @class = "btn btn-info" })

如何查看数据基于今天的日期或从统计表中读取数据,有日期列,但是问题在另一个视图中,我无法分配值

项。

以前我该如何做并查看数据取决于今天的日期?

I need to view the data based on today date only

This is the controller code :

  public ActionResult Edit(int programId, int hospitalNo  ,DateTime CountDate )
        {
            var stat = _context.STATISTICS.Where(d => d.program_id == programId && d.hospital_no == hospitalNo && d.DATE == CountDate).ToList();
            return View(stat);
           
        }

and this is the button which open the view :

I created session parameter saving login date and tried to call it but its not working :

  Session["LoginDate"] = DateTime.Now.ToShortDateString();

    @Html.ActionLink("Statistics", "Edit","Statistics", new {programId  = item.program_id, hospitalNo = item.hospital_id ,CountDate = Convert.ToDateTime(Session["LoginDate"]) }, new { @class = "btn btn-info" })

How can I view the data based on the today date or read the data from STATISTICS table there is DATE column but the issue the button in another view and I cannot assign the value

item.DATE

How can I do it and view the data depends on today date ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2025-02-19 07:12:08

您在操作链接中传递的数据将通过查询参数传递到控制器,并且系统只能在此处读取字符串和整数。您试图尝试在查询参数中传递C#对象,这就是为什么它可能对您不起作用的原因。我建议您更改下面的按钮代码:

Session["LoginDate"] = DateTime.Now.ToShortDateString();

@Html.ActionLink("Statistics", "Edit","Statistics", new {programId  = item.program_id, hospitalNo = item.hospital_id ,CountDate = Session["LoginDate"]), new { @class = "btn btn-info" })

以及您的控制器代码如下:

 public ActionResult Edit(int programId, int hospitalNo  ,string CountDate )
    {
        var stat = _context.STATISTICS.Where(d => d.program_id == programId && d.hospital_no == hospitalNo && d.DATE == DateTime.Parse(CountDate)).ToList();
        return View(stat);
       
    }

the data that you pass in Action Link , will pass on to the controller via query params and the system could read only string and integers there. What you are trying to attempt is to pass a C# object in query params, which was why it might not be working for you. I would suggest you to change your button code like to below:

Session["LoginDate"] = DateTime.Now.ToShortDateString();

@Html.ActionLink("Statistics", "Edit","Statistics", new {programId  = item.program_id, hospitalNo = item.hospital_id ,CountDate = Session["LoginDate"]), new { @class = "btn btn-info" })

and your controller code like below:

 public ActionResult Edit(int programId, int hospitalNo  ,string CountDate )
    {
        var stat = _context.STATISTICS.Where(d => d.program_id == programId && d.hospital_no == hospitalNo && d.DATE == DateTime.Parse(CountDate)).ToList();
        return View(stat);
       
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文