Can I Allow my RouteTemplate to Being With an '/' Character?

0

I have the following method within my API controller in an AngularJS WebAPI/MVC project:

        [Route("GetRecordByID/{metricID:string}")]
    [ResponseType(typeof(Metric_Approval_Data))]
    [HttpGet]
    public Metric_Approval_Data GetRecordByID(string metricID)
    {
        Metric_Approval_Data arecord = null;
        try
        {
            arecord = dbContext.Metric_Approval_Data.Where(x => x.Metric_ID == metricID).SingleOrDefault();
        }
        catch (Exception e)
        {
            arecord = null;
        }

        return arecord;
    }

This method should work correctly however when I build and run my project I am met with the following error:

System.InvalidOperationException HResult=0x80131509 Message=The route template '/api/Record/GetRecordByID/{metricID:string}' on the action named 'GetRecordByID' cannot start with a '/' character.

Currently I am unable to find a fix or some documentation for this Issue and was wondering if there is a simple workaround for this or I need to use a CAST at some point?

Any help is appreciated :)

c#
angularjs
asp.net-mvc
asp.net-web-api
controller
asked on Stack Overflow Oct 28, 2020 by Joseph Burke

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0