Click here to Skip to main content
Sign Up to vote bad
good
See more: C#MVCjQuery
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.
Posted 28-Dec-12 2:32am
Shiv19368

Comments
digimanus - 28-Dec-12 8:33am
what have you tried?
Sandeep Mewara - 28-Dec-12 9:00am
It does not work like this here. Here is what is expected of enquirers: 1. TRY first what you want to do! You may find that it's not that hard. 2. Formulate what was done by you that looks like an issue/not working. Try them and tell if you face issues. Members will be more than happy to help like this.
Shiv19 - 17-Jan-13 9:47am
Thanks for the heads up!!!As if I did not do anything before posting. It would be better if refrain from commenting and focus more on ANSWERING.
Sandeep Mewara - 17-Jan-13 10:06am
If you did anything, your question would have said so. :) Enjoy.
Shiv19 - 18-Jan-13 9:46am
Brains are required to understand questions and answer them like those who have already answered.;) Cheers!!!
Sandeep Mewara - 18-Jan-13 10:26am
Yeah Sure. Cheers.

3 solutions

Hi,
 
What I was using was
 
<!doctype html>
 
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Datepicker - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
    </script>
</head>
<body>
 
<p>Date: <input type="text" id="datepicker" /></p>
 

</body>
</html>
 

Here instead of using the <input /> tag I want to use Razor code...For eg, @Html.TextBoxFor but with razor code the Datepicker does not get displayed.
  Permalink  
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>

 

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',
            success: function (jsonData) {
                //her you provide logic for display data
            }
        });
  Permalink  
//your method

public JsonResult function_Name(DateTime from, DateTime to)
{
List Data= // method will return a list of exams
return this.Json(Data,JsonRequestBehavior.AllowGet);
}
and coding in your view
$.ajax({
type: 'Post',
url: 'your Url',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (jsonData) {
//her you provide logic for display data
}
});
 
and also include jquery plug in that suppoet ajax .
this is running project code please give your review
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 514
1 Ron Beyer 296
2 OriginalGriff 248
3 samadhan_kshirsagar 229
4 Tadit Dash 213
0 Sergey Alexandrovich Kryukov 7,017
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,372
4 CPallini 3,010


Advertise | Privacy | Mobile
Web02 | 2.6.130619.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid