简体   繁体   English

两个日期之一在Portablerest帖子中丢失

[英]One of two dates gets lost in portablerest post

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. 我正在尝试将模型发布回我的mvc Web API控制器,并且当它离开xamarin.forms方法时,我的结束日期就在那里。 Once I hit my breakpoint on the web api controller, the end date is the default "01/01/0001" and gives me an error. 一旦我在Web api控制器上达到断点,结束日期就是默认的“ 01/01/0001”,并给我一个错误。 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. 我在xamarin端击中断点,一切都正确。 I go from there to the web api controller and end time is lost. 我从那里转到网络api控制器,结束时间丢失了。 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. 我尝试了Fiddler来捕获发布的内容,但是无法从xamarin.forms应用程序中看到它。 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: 以下是几个屏幕截图,显示了在控制器之前,然后在控制器上的值:

在此处输入图片说明 在此处输入图片说明

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;
        }

    }

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. 我意识到发生了什么...。我的日期在我的MVC模型上被称为end_date,在我的移动模型上被称为end_time。 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. 从Web到移动设备都很好,但是尝试将其发送回API,它不喜欢名称差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM