One of two dates gets lost in portablerest post

86 views Asked by At

I'm trying to post my model back to my mvc web api controller, and when it leaves my xamarin.forms method, my end date is there. Once I hit my breakpoint on the web api controller, the end date is the default "01/01/0001" and gives me an error. I'm not sure how to track this down and see where the problem is. I hit the breakpoint on the xamarin side and everything is correct. I go from there to the web api controller and end time is lost. My start time date is still there, I'm just losing one date and I have no idea why. I've tried Fiddler to capture whats being posted but can't see it from the xamarin.forms app. Is there another option to capture this? Am I missing something? Here are a couple screen shots showing the values right before it goes to the controller, and then at the controller:

enter image description here enter image description here

Here is the code on each side:

public async void OnSaveClicked()
    {
        var url = BaseUrl + "/classapi/ClassEdit?"; //+  classToEdit.ToString();
        //var client = new HttpClient() { BaseAddress = new Uri(url) };
        //client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json"));
        var client = new RestClient
        {
            BaseUrl = url
        };

        var request = new RestRequest("", HttpMethod.Post)
        {
            ContentType = ContentTypes.Json,
            ReturnRawString = true
        };
        request.AddParameter("class", classToEdit);


        var result = await client.ExecuteAsync<string>(request);


        classToEdit = JsonConvert.DeserializeObject<m_class>(result);

        if (classToEdit != null)
            DisplayAlert("Class Edit", "Class was successfully saved.", "OK");
    }

Controller:

 [ActionName("ClassEdit")]
    public int ClassEdit(t_class mobileClass)
    {
        mobileClass.color = "";
        if (ModelState.IsValid)
        {
            db.Entry(mobileClass).State = EntityState.Modified;
            db.SaveChanges();
            return 1;
        }
        else
        {
            return 0;
        }

    }
1

There are 1 answers

0
Parker3306 On BEST ANSWER

I realized what was going on.... my date was called end_date on my MVC model and it was called end_time on my mobile model. It was going from web to mobile just fine, but trying to send it back to the API, it didn't like the name difference.