我如何在ASP.NET MVC中按开始和结束日期过滤数据 [英] How I can filter data by start and end date in ASP.NET MVC

查看:83
本文介绍了我如何在ASP.NET MVC中按开始和结束日期过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我想创建像这个演示我不知道我怎么能在asp.net mvc实体框架中做到这一点



https://i.stack.imgur.com/XdNdN.gif [ ^ ]



我尝试了什么:



Hello ,

I want to create like this demo i do not know how i can do that in asp.net mvc entity framework

https://i.stack.imgur.com/XdNdN.gif[^]

What I have tried:

This is my view :

<pre>@using (Html.BeginForm())
{
        <div>
            <span>Start Date :</span> <input type="date" name="start" />
            <span>End Date :</span> <input type="date" name="end" />
            <input type="submit" value="Get Records Between Dates" />
        </div>
        <table>
        @foreach (var item in Model)
        {
            <tbody>
               <tr>
                    <td>
                         @Html.DisplayFor(modelItem => item.expenses.Expenses_Type)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.DateExpense)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Amount)
                    </td>                           
            </tbody>
         }
        </table>

}





这是我的控制器:





And this my controller :

public ActionResult Index(DateTime? start, DateTime? end)
   {
       var ExpenseDetails = _context.ExpenseDetails.Include(s => s.expenses).ToList();

       return View(ExpenseDetails);
   }

推荐答案

首先,你需要一个控制器,它将日期作为参数,它们被发布在你的表格。然后,您需要查询数据以获取日期之间的值。



您发布的代码似乎合理。如果你需要帮助,你需要说的不仅仅是不起作用。告诉我们你的尝试。日期时间是否被发送到后端?如果没有,你是否使用Fiddler查看发布的内容?



我认为你可能需要为这些值设置'id'和'name'被张贴?
First, you need a controller that takes the dates as parameters, they are posted on your form. Then you need to query your data to get values between the dates.

The code you posted seems reasonable. If you want help, you need to say more than 'does not work'. Tell us what you tried. Are the date times being sent to the back end? If not, have you used Fiddler to see what is being posted?

I think you may need to set 'id' as well as 'name' for the values to be posted?


这篇关于我如何在ASP.NET MVC中按开始和结束日期过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆