使用两个日期搜索 [英] Search using two dates

查看:60
本文介绍了使用两个日期搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有两个日期字段。从日期:到日期:字段。现在我想使用这个日期在控制器中触发一个Action,以检索各自日期落在这些日期之间的结果。我很感激使用JQuery。



先谢谢。



Shiv。

Hi,

I have two date fields. FROM DATE: and TO DATE: fields. Now I want to use this dates to fire an Action in the controller to retrieve results which have their respective dates falling in between these dates.I would appreciate the use of JQuery.

Thanks in Advance.

Shiv.

推荐答案

就你想要的而言在JQuery的帮助下得到这些数据,我建议用U />
代替Action返回Json数据。

例如假设我们有这样的实体

Hi , as far as you would like to get this data with help of JQuery , i suggest to U
instead of Action return Json data.
For example lets assume that we have such entity
public class Exam
    {
        public DateTime To { get; set; }
        public DateTime From{ get; set; }
        public string Description { get; set; }
        public int Score { get; set; }
    
    }





所以我们定义我们的控制器:



so lets define our controller:

public class ExamController:Controller
{
 
public JsonResult GetExams([FromUri]DateTime from, [FromUri]DateTime to)
 {
  List<exam> exams = Exams.GetExams(from, to); // method will return a list of exams
  return this.Json(exams,JsonRequestBehavior.AllowGet);
 }
}</exam>







剩下的最后一件事是拨打ajax电话在jquery的帮助下:




and the last thing that remains is to make ajax call with help of jquery:


.ajax({
type:' GET'
url:' / Exam / GetExams'
data:json,
contentType:' application / json; charset = utf-8'
成功: function (jsonData){
// 她为显示数据提供逻辑
}
});
.ajax({ type: 'GET', url: '/Exam/GetExams', data: json, contentType: 'application/json; charset=utf-8', success: function (jsonData) { //her you provide logic for display data } });


//你的方法



public JsonResult function_Name(DateTime from,DateTime to)

{

List< nameofclass> Data = //方法将返回一个考试列表

返回this.Json(Data,JsonRequestBehavior.AllowGet);

}

和编码在您看来
//your method

public JsonResult function_Name(DateTime from, DateTime to)
{
List<nameofclass> Data= // method will return a list of exams
return this.Json(Data,JsonRequestBehavior.AllowGet);
}
and coding in your view


这篇关于使用两个日期搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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