C# 服务器仅在调试时引发异常
我有一个api调用来从我的数据库中搜索一个包含3个字段的对象。(字符串、datetimestart、datetimeend)。 当我执行此操作时,它可以完美地工作:C# 服务器仅在调试时引发异常,c#,debugging,null,C#,Debugging,Null,我有一个api调用来从我的数据库中搜索一个包含3个字段的对象。(字符串、datetimestart、datetimeend)。 当我执行此操作时,它可以完美地工作: entryAPI.entriesSearch = function (item) { return $http.post("./api/search/", { Matter: item.Matter, StartDate: item.StartDate, EndDate: item.EndDate}); }; 问题是,当我
entryAPI.entriesSearch = function (item) {
return $http.post("./api/search/", { Matter: item.Matter, StartDate: item.StartDate, EndDate: item.EndDate});
};
问题是,当我附加调试器并在调用中放置断点时,接收的项似乎为null,显然它会引发异常
public HttpResponseMessage Post(Entities.TimeSheet.SearchFields item)
{
try
{
// do some stuff (that is correctly done when not debugging
// item value is null when debugging
}
这是我的SearchFields项目:
public class SearchFields
{
public string Matter { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
搜索工作非常好,但我现在想跟踪一些值,但我无法这样做,我不知道如何解决/搜索如何解决类似的问题
提前谢谢。我想[FromBody]不见了 比如:
我认为[FromBody]不见了 比如:
如果将
{Matter:item.Matter,
替换为item={Matter:item.Matter,…
?使用Fiddler检查实际发送到应用程序的内容以及调用之间的差异。MVC的数据绑定在调试过程中不会改变行为。由于使用了/api/search
,有效URL可能不同。或者数据可能不同。如果替换{Matter:item.Matter,…
withitem={Matter:item.Matter,…
?使用Fiddler检查真正发送到应用程序的内容以及调用之间的差异。MVC的数据绑定在调试过程中不会改变行为。由于使用/api/search
,有效URL可能会有所不同。或者数据可能会有所不同。这完全解决了。这是正确的奇怪的是,我接到另一个电话,要求发布项目本身,但没有“frombody”。我认为这只对主要类型是必要的。真的非常感谢。我也做过同样的事情:-)你很好,这完全解决了。奇怪的是,我接到另一个电话,要求发布项目本身,但没有“frombody”.我认为这只对初级类型才有必要。真的非常感谢。我也做过一次:-)你很好
public HttpResponseMessage Post([FromBody] Entities.TimeSheet.SearchFields item)
{
try
{
// do some stuff (that is correctly done when not debugging
// item value is null when debugging
}