Need good guidance to MVC 5 Web API route conifguration

Hi,

I'm writing my first MVC5 API in Visual Studio 2017 and C#.  I'm not doing this in .net Core because I need to use CSOM, SharePont online Client object to update SharePoint online Document Library column data and that is no yet supported in .net Cored.

I seem to understand more about MVC routing in regular Controller and Actions but I'm very lost in the API configuration.  I used the MVC WEB API template and created the basic Get, ..post...Put..Delete....   public method under my API.

The first one method I want to do is to perform an update on a column data on the SPO Document Library's column.  I supposed that would be the Put method?  Or can I rename that method?  I coded my method as below and when I put in http it just defaults to the first Get method with no parameter.  What should I add in the WebApiConfig.cs for this to work.  I'm passing in a string value like "True" or "False", the method then assign this string to the column data of the document library.  The problem is it's not even getting hit.

I read a couple of article online which kept sending me to another link, another....  I'm just very confused and still don't know how to setup the WebApiConfig.cs

Before the declaration of my public API class, I have

[RoutePrefix("api/SetFlags")]

        // PUT api/<controlle
        // PUT api/<controller>/False
        [Route("{string:flagValue}")]
        public void Put(string flagValue)
        {
            List pnpList = pnpContext.Web.Lists.GetByTitle("GetAlarmsListing");
            CamlQuery query = CamlQuery.CreateAllItemsQuery();
            ListItemCollection allPnpDocs = pnpList.GetItems(query);
            pnpContext.Load(allPnpDocs);
            pnpContext.ExecuteQuery();

            foreach (ListItem pnpDoc in allPnpDocs)

          {
                pnpDoc["90DaysAlarmSent"] = flagValue;
                pnpDoc["Title"] = flagValue;//30DaysAlarmSent
                pnpDoc.Update();
            }

            pnpContext.ExecuteQuery();
        }

Open in new window


Thank you.
lapuccaAsked:
Who is Participating?
 
AZZA-KHAMEESCommented:
Change the method signature like this:

public void Put(string id)
{
    // your rest of the coding here..
}

It's because your Web API Configuration will expect a default parameter with a name "id".

Hope this would help!

Good Luck,
0
 
lapuccaAuthor Commented:
Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.