locked
Route string parameter RRS feed

  • Question

  • I have an angular with MVC application. I have problem to pass a string parameter to “Route”.  If I make the parameter a integer (remove // in front of the dates = 30), then it works. However, the parameter should be a string that contains the start and end dates. If I pass the original string parameter, the OrdersController.cs never be called. Please help me out what should I do. I am new in AngularJS and MVC and just try to modify an exit applications. Many thanks.

    OrderListController.js

    var dates = startDate + "|" + endDate;       // “1/1/2017|7/12/2017”

    vm.getOrdersByScope = function () {

        DataService.getOrdersByScope(dates)                          

       .then(function (response) {

    }

    DataService.js

    dataService.getOrdersByScope = function (dates) {

       //dates = 30;

       return $http.get('/Purchase/api/orders/' + dates); 

    };         

    OrdersController.cs

    [Route("orders/{fromto}")]       

    public IHttpActionResult GetLatestRequestByDays(string fromto)

    {

      

    }

    • Moved by CoolDadTx Thursday, July 13, 2017 2:05 PM ASP.NET related
    Wednesday, July 12, 2017 7:30 PM

Answers

  • Hi eg10013,

    please pay attention to the format of dates .It includes '/' character ,and the program parse the route by the '/' character ,this is the reason why you didn't get the date . You could fix it through many ways.

    1.modify the format of dates

    var dates = "1-1-2017|7-12-2017"

    2.Or you could pass values as url parameter

    var dates = "1/1/2017|7/12/2017"
    $http.get('/orders/?' + 'fromto=' + dates); 

    the controller code:

    [Route("orders")]
    public IHttpActionResult GetLatestRequestByDays(string fromto)
                    {
                    }

    the result:

    If you have any issues, please feel free to contact me.

    Best regards,

    feih-7


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by eg10013 Thursday, July 13, 2017 2:07 PM
    Thursday, July 13, 2017 8:37 AM

All replies

  • Can you show how your routing configuration looks like ?

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, July 13, 2017 7:33 AM
  • Hi eg10013,

    please pay attention to the format of dates .It includes '/' character ,and the program parse the route by the '/' character ,this is the reason why you didn't get the date . You could fix it through many ways.

    1.modify the format of dates

    var dates = "1-1-2017|7-12-2017"

    2.Or you could pass values as url parameter

    var dates = "1/1/2017|7/12/2017"
    $http.get('/orders/?' + 'fromto=' + dates); 

    the controller code:

    [Route("orders")]
    public IHttpActionResult GetLatestRequestByDays(string fromto)
                    {
                    }

    the result:

    If you have any issues, please feel free to contact me.

    Best regards,

    feih-7


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by eg10013 Thursday, July 13, 2017 2:07 PM
    Thursday, July 13, 2017 8:37 AM
  • Please post questions related to MVC in the ASP.NET forums.
    Thursday, July 13, 2017 2:05 PM
  • Thank you feih-7. Yes, the '/' was the issue. I changed it to '-' that works.
    Thursday, July 13, 2017 2:07 PM