Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am having problem in mvc 4 web api (c#)

I have a following web api controllor and action

C#
public abcapicontroller:apicontroller
{

        public IEnumerable<viewmodel> pqrAction(int id,string CustName,datetime BillDate)
          {
               ------------ some code 
                 Return jsonobject;
           }

 
}


My problem is

1. I want to call web api from web browser address bar as

http://localhost:protno/api/abcapi/pqrAction/1/Ram/2014-02-21T23:51:32:031Z

Where
api/C***rollerName/ActionName/id/CustName/Datetime(universal)

In web browser address bar 2014-02-21T23:51:32:031Z format not working (only 2014-02-21 working)

2. and want to use above url in jquery post as follows


JavaScript
function GetCustomerDetail() {
        jQuery.support.cors = true;
        var CustData= {
            ID: 1,
            CustName: "Ram",
            BillDate: "2014-02-21T23:51:32:031Z"
            
        };       
        
        $.ajax({
            url: 'http://localhost:protno/api/abcapi/pqrAction',
            type: 'POST',
            data:JSON.stringify(employee),            
            contentType: "application/json;charset=utf-8",
            success: function (CustData) {
                 do some thing
            },
            error: function (x, y, z) {
               
            }
        });
    }



How can I Achieve my task any url routing pattern or other i need to do ..... ? please help me.


with Regards,
Manoj
Posted

1 solution

You can't use ":" in the Url - it won't work.
Instead, why not your the value that DateTime is based around: the Ticks property? It's an Int64 value so there is no problem in transferring it around, and DateTime has a constructor which works from it directly.
 
Share this answer
 
Comments
George Jonsson 6-Sep-14 4:55am    
Good answer.
Manoj Kumar Choubey 12-Sep-14 0:52am    
it is working when i pass as parameter : [FromUri]string Datetimevalue
and In web.config I need to put
<compilation debug="true" targetframework="4.5.1">
<httpruntime targetframework="4.5.1" requestpathinvalidcharacters="">
Is it will give any problem in future ?

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