Click here to Skip to main content
15,885,948 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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
Comments
Herman<T>.Instance 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!!!

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
C#
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:
C#
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:
JavaScript
$.ajax({
           type: 'GET',
           url: '/Exam/GetExams',
           data: json,
           contentType: 'application/json; charset=utf-8',
           success: function (jsonData) {
               //her you provide logic for display data
           }
       });
 
Share this answer
 
//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
$.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
 
Share this answer
 
Hi,

What I was using was

XML
<!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 tag I want to use Razor code...For eg, @Html.TextBoxFor but with razor code the Datepicker does not get displayed.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900