ASP.NET MVC Pass datetime as request

How to convey a date, for example. 01/01/2011 21:01:34how is the query string?

I am creating a website for movie theater reservations, and while watching performances, I am currently broadcasting the show and the venue, but I must also transmit the date (as this is a unique part of the performance)

ActionResult looks like this:

public ActionResult Details(String name, String venue, String date)
{
    return View(_repository.performanceDetails(name, venue, date));
}

But it performanceDatedoes not work, because it is a datetime data type! What I need to do is REMOVE the temporary part of the data, for example. 00:00:00and somehow pass the remaining data as a string, which I can use for comparison like this:

public PerformanceDetails performanceDetails(String name, String venue, String date)
{
    var PerformanceDetails = (from s in _db.PerformanceDetails
                              where s.show == name && 
                                    s.venue == venue && 
                                    s.performanceDate == date
                              select s).First();
    return PerformanceDetails;
}

Here is an example link:

<%= Html.ActionLink("View Details", "Details", "Performances", 
                    new { 
                        name = item.show, 
                        venue = item.venue, 
                        date = item.performanceDate }, 
                    new {@class = "button"}) %>
+5
source share
3 answers

Try putting the date in the query string in a format like this:

item.performanceDate.ToString("dd-MMM-yyyy")

URL- ( ):

http://foo/Performance/Details?name=someName&venue=someVenue&date=31-Mar-2011

, , / ( ). - .

ActionMethod TryParse() Parse() .

var dt = DateTime.Parse(date);

LINQ - :

&& s.performanceDate == dt 

, :

public ActionResult Details(String name, String venue, String date)
{
    DateTime dt;

    if (DateTime.TryParse(date, out dt))
    {
        return View(_repository.performanceDetails(name, venue, dt));    
    }
    else
    {
        return View("Error", "The value passed in date isn't a date value.");
    }
}

public PerformanceDetails performanceDetails(String name, String venue, DateTime dt)
{
    var PerformanceDetails = (from s in _db.PerformanceDetails
                              where s.show == name && 
                                    s.venue == venue && 
                                   s.performanceDate == dt.Date                  
                              select s).First();
    return PerformanceDetails;

}

<%= Html.ActionLink("View Details", "Details", "Performances", 
                new { name = item.show , 
                      venue = item.venue, 
                      date = item.performanceDate.ToString("dd-MMM-yyyy") }, 
                new {@class = "button"}) %>
+4

-, Action DateTime, . , ISO 8601 (http://en.wikipedia.org/wiki/ISO_8601), : 2011-10-17T12: 35:00.

- . , hh: mm: ss, . "Z".

, , , mydate.Date.

+5

. - , . , , , URL- Action.

Int64 ticks = dateOfShow.Ticks;

DateTime newDateOfShow = new DateTime(ticks);
+2

All Articles