Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MVC jQuery
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 3:32am
Shiv19384
Comments
digimanus at 28-Dec-12 8:33am
   
what have you tried?
Sandeep Mewara at 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 at 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 at 17-Jan-13 10:06am
   
If you did anything, your question would have said so. :)
 
Enjoy.
Shiv19 at 18-Jan-13 9:46am
   
Brains are required to understand questions and answer them like those who have already answered.;)
Cheers!!!
Sandeep Mewara at 18-Jan-13 10:26am
   
Yeah Sure. Cheers.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

//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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100