本文介绍了ASP.NET MVC核心Web POST请求使用NULL值填充数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 场景 我正在建立一个博客,并正在配置一个页面以将编辑后的评论发布到MsSql服务器。 问题 在我提交提交表单POST之后,通过我的视图,应该捕获并通过此表单返回的属性值全部返回为 NULL!由于我的数据模型中存在NULL值,最终将导致异常错误。在浏览完整个应用程序并使用Fiddler之后,我无法诊断问题。 快速可视化示例 提交 POST 后(运行时),并且我的应用程序已到达 Home Controller 在我的博客上,这是显示和可用的内容。 捕获的表单数据-通过Visual Studio的本地检查器查看 收到POST数据在家用控制器中 注意:如您所见,每个输入的该值在运行时由Home Controller捕获。但是,此数据不会在 POST 后发送到 EditComment 方法。 进程 使用我的模型的属性值填充输入控件,然后提交: EditComments.cs @model MpComment ... HTML内容... < form asp-controller = Home asp-action = EditComment method = post类=文本危险输入表单> < div asp-validation-summary = ModelOnly>< / div> < div class = form-group> < label asp-for =< Model.Property> class = control-label>< / label> < input asp-for =< Model.Property> class = form-control /> < span asp-validation-for =< Model.Property> class = text-danger>< / span> < / div> ... ASP表单输入元素... < div class = form-group input-submit> < input type = submit value = Submit class = btn material-button /> < / div> < / form> 我的AppDbContext已初始化 AppDbContext.cs namespace Portfolio.Data {公共类AppDbContext:IdentityDbContext { public AppDbContext(DbContextOptions< AppDbContext> options):基本(选项){} 公共虚拟DbSet< MpPost> MpPost {get;组; } 公共虚拟DbSet< MpComment> MpComment {get;组; } 公共虚拟DbSet< MpGuest> MpGuest {获取;组; } 公共虚拟DbSet< MpLogin> MpLogin {get;组; } 公共虚拟DbSet< MpProject> MpProject {get;组; } } } 我的MpComments模型开始出现并 使用系统;设置每个属性值,但是填充每个属性的数据为NULL。 使用System.ComponentModel.DataAnnotations; 命名空间Portfolio.Models {公共部分类MpComment { public int Id {get;组; } public int Mp_Post_Id {get;组; } public int Mp_Guest_Id {get;组; } public string评论{get;组; } public int?因果报应{get;组; } public int?已批准{得到;组; } 公共字符串Ip {get;组; } 公共字符串Agent {get;组; } 公共DateTime?创建{get;组; } = DateTime.Now; 公共DateTime?更新{get;组; } = DateTime.Now; } } 一旦没有任何填充,则启动Home Controller,并调用以下函数: HomeController.cs [HttpPost] 公共异步任务< IActionResult> EditComment(MpComment评论) { comment.Id = 0; _repo.AddComment(comment); if(await _repo.SaveChangesAsync()) return RedirectToAction( ViewComments); else return View(comment); } 此时是 comment 参数变量从POST填充的值仅包含NULL值,并且显示如下: 调查和分析 VisualStudio 局部变量检查器 代理null 批准的null 评论null 创建{6/30/2019 1 :04:29 PM} Id 0 Ip null 因果报废 Mp_Guest_Id 0 Mp_Post_Id 0 更新{6/30/2019 1:04 :29 PM} 此过程在设置为实现此完全相同功能的其他过程中均按预期工作 例如,这是Fiddler在成功的POST中从几乎相同的POST过程中捕获的内容: 提琴手检查器 原始(EditProject成功) POST https:// localhost:44390 / Home / EditProject / 21 HTTP / 1.1 主机:localhost :44390 连接:保持活动状态内容-长度:555 缓存控制:max-age = 0 来源:https:// localhost:44390 升级-不安全请求:1 内容类型:application / x-www-form-urlencoded 用户代理:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,例如Gecko)Chrome / 75.0.3770.100 Safari / 537.36 接受:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng ,* / *; q = 0.8,application / signed-exchange; v = b3 推荐人:https:// localhost:44390 / Home / EditProject / 21 Accept-Encoding:gzip,deflate,br 接受语言:EN-US,EN; q = 0.9,MT; q = 0.8 曲奇:.AspNetCore.Antiforgery.x5eNnYCJ5UA = CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application = CfDJ8OfA6sTjcU1PuqxxzGM-oMp2YqORrHzf5IL0rLJ8jvAP-RYvHIXeH63EfD3-TugdZGBP9nf_lHhAn71ACsIQZe_cJ1x7u3FBh25uhlXZIJX9yk7ZdH_GuwfYEe-Zaa1CSAD2f2g8U7syt8jvxy18c-qCN9Yq2zLQpBeOlzftudcaMKKrsA-UGO8BOHLPTk1TYe1QMosDGaFDLXY0POqCpluxiiA0qsA0i9iQeAP6HL7ZC8lLjf76Lf_E5usVyakwa9X3ELDJQeaEFFa5Vi_5063xCHhm3NRREE5loUCff1rKmaOKvvOR-FNF-QtYLG-MGthgVAGah4cdXjD0jsKFBM0Ny-Yt8uRddQ26w_8AUJqhRo9jOAXEuzyhYwPRfKQKykgpy-4lVIZXc2QR25EWxq9H6zh5GGCTIitxISDcpoHf0mUqzT9aJKo_LwB6cibzbDwBmVsTc6Yn6cQA0MMoBVa6E6hKuvQoNerU7psX5z2D2k8tB8mZVlJQ3medeMwHQonOSBh99OxOrBO5K6iedlpPqSNco8r7PbNcHCdhLKehtoyJkE3tzmrv_EOTAS7ldXNhhPHqNp_RmuAdGWlsJ-A-bN5itj1hv_o7RCxl8t49XB9oddsg4iOvR-BUZOLuxJKfQ90PAH4S9BvblwLKoXx3Gt3We5WeG8Ga6rAXHQhd 的ID = 0&安培;名称= Product + Engineer& Desc = nulla + neque + libero + convallis + eget + eleifend& Live_Url = bloglovin.com%2Feget%2Ftincidunt%2Feget.jpg& Github_Repo = sourceforge.net%2Fet%2Fultrices%2Fposuere%Re = 2Fcubilia。 creativecommons.org%2Fpede%2Fli BERO%2Fquis.html和放大器;创建= 2011-07-11T00%3A00%3A00.000和放大器;更新= 2019-06-20T00%3A00%3A00.000和放大器; __ RequestVerificationToken = CfDJ8OfA6sTjcU1PuqxxzGM-oMqTHmlRblU70EY0Ou7tH2IifiXdJOCtMRepfMg-GhKz-j4at6h9BOzJTNjHIROMjDpUiOqxvDeGWcja8K-uGkYrW8DX58j9mIFlwKML9tLVtvusmGmPekVMPxYqRkKdcyLGb6qpav3upDLAvfxLblbs9RynCyG4bDTAAZ4jzxc-WW 提琴手检查器 原始(编辑注释失败) POST https:// localhost:44390 / Home / EditComment / 1 HTTP / 1.1 主机:localhost:44390 连接:keep-alive 内容长度:606 缓存控制:最大年龄= 0 来源:https:// localhost:44390 升级-不安全请求:1 内容类型:application / x-www-form-urlencoded User-Agent :Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,例如Gecko)Chrome / 75.0.3770.100 Safari / 537.36 接受:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng ,* / *; q = 0.8,application / signed-exchange; v = b3 推荐人:https:// localhost:44390 / Home / EditComment / 1 Accept-Encoding:gzip,deflate,br 接受语言:EN-US,EN; q = 0.9,MT; q = 0.8 曲奇:.AspNetCore.Antiforgery.x5eNnYCJ5UA = CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application = CfDJ8OfA6sTjcU1PuqxxzGM-oMp2YqORrHzf5IL0rLJ8jvAP-RYvHIXeH63EfD3-TugdZGBP9nf_lHhAn71ACsIQZe_cJ1x7u3FBh25uhlXZIJX9yk7ZdH_GuwfYEe-Zaa1CSAD2f2g8U7syt8jvxy18c-qCN9Yq2zLQpBeOlzftudcaMKKrsA-UGO8BOHLPTk1TYe1QMosDGaFDLXY0POqCpluxiiA0qsA0i9iQeAP6HL7ZC8lLjf76Lf_E5usVyakwa9X3ELDJQeaEFFa5Vi_5063xCHhm3NRREE5loUCff1rKmaOKvvOR-FNF-QtYLG-MGthgVAGah4cdXjD0jsKFBM0Ny-Yt8uRddQ26w_8AUJqhRo9jOAXEuzyhYwPRfKQKykgpy-4lVIZXc2QR25EWxq9H6zh5GGCTIitxISDcpoHf0mUqzT9aJKo_LwB6cibzbDwBmVsTc6Yn6cQA0MMoBVa6E6hKuvQoNerU7psX5z2D2k8tB8mZVlJQ3medeMwHQonOSBh99OxOrBO5K6iedlpPqSNco8r7PbNcHCdhLKehtoyJkE3tzmrv_EOTAS7ldXNhhPHqNp_RmuAdGWlsJ-A-bN5itj1hv_o7RCxl8t49XB9oddsg4iOvR-BUZOLuxJKfQ90PAH4S9BvblwLKoXx3Gt3We5WeG8Ga6rAXHQhd Mp_Post_Id = 1&安培; Mp_Guest_Id = 1和注释= lorem + quisque + ut + erat + curabitur + gravida + nisi + at + nibh + in + hac + habitasse + platea + dictumst + aliquam& Karma = 1&已批准= 1& Ip = 21.99.31.96& Agent = Mozilla%2F5.0 +%28Macintosh%3B + U%3B + Intel + Mac + OS + X + 10_7%3B + zh-cn%29 + App leWebKit%2F533.4 +%28KHTML%2C + like + Gecko%29 + Version%2F4.1 + Safari%2F533.4& Create = 2018-07-17T00%3A00%3A00.000& Update = 2012-06-01T00 %3A00%3A00.000&安培; __ RequestVerificationToken = CfDJ8OfA6sTjcU1PuqxxzGM-oMquggjJDBhMvQwfCKwHRJS9tJeBi-4bT19jJVjuUjZgYE1LD4BvCF2LBJlQ45u3d9sEGmm-l9EAhbXaA2TwuNjW4xhYpVXl4Z0YE_YBEvbuSzodxjP8v1GoYAXYfs5yl3L39SK0gp1YKkkwujMhdExO17v3n-b_y4IhhZJ3SanIZw 注意:除了在POST URL上存在差异外,其他所有内容(应在此处显示)都相同。每次对此进行故障排除时,我都会输入第一个条目,对其进行编辑,然后提交。每次执行此操作时(在其他四个可以正常工作的过程中),它都会迭代到下一个条目; 示例: A)编辑和在有 20个项目条目 时提交项目1 : POST https: // localhost:44390 / Home / EditProject / 21< ===差异 B)编辑并放大;当有 20条评论条目 时,提交评论1 : POST https: // localhost:44390 / Home / EditComment / 1< ===差异 Chrome (网络标题) 成功(项目) 常规:请求URL:https:// localhost:44390 / Home / EditProject / 66 请求方法:POST 状态码:302 远程地址:[:: 1]:44390 推荐人策略:no-referrer-when-downgrade ------- -------------------------------------------------- ------------------------------------------ 响应标题:内容长度:0 日期:2019年7月1日星期一00:04:16 GMT 位置:/ Home / ViewProjects 服务器:Kestrel 状态:302 x-技术支持:ASP.NET x-sourcefiles:=?UTF-8?B?QzpcV29ya3NwYWNlXHd3d1xhc3BcUG9ydGZvbGlvXFBvcnRmb2xpb1xIb21lXE VkaXRQcm9qZWN0XDY2?= ------------------------------------------- -------------------------------------------------- ------ 请求标头::授权:本地主机:44390 :方法:POST :path:/ Home / EditProject / 66 :scheme :https 接受:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng,* / *; q = 0.8,application / signed-exchange; v = b3 accept-encoding:gzip,deflate,br accept-language:zh-cn,en; q = 0.9,mt; q = 0.8 cache-control:max-age = 0 内容长度:1200 内容类型:application / X WWW的窗体-urlencoded 饼干:.AspNetCore.Antiforgery.x5eNnYCJ5UA = CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application = CfDJ8OfA6sTjcU1PuqxxzGM-oMpTJYFjUyUy3eLO3fbnX9V4SSq14P_h_AlTAyZs-9LrMW9QOzTP46d8CJetHqzamw-ulm6IbjGyC_hElFiwtJRbKAV3GuVlGQeNfbhcJ7M81EH4bqnbi-NBwP4nmlXROTG3DvMYdHqC1-eqT53ip4mnHpdLDLKlwX80Lk8uWPpiyD5L_RFiMGl5i0vOUz19bbn-mSC3IVbuGz8LeDePfKDmU-3b8_sNiZJpBpx4p6jORrds69LkpkdZX2NUWzyevM4TWw8irVRRBY0PAFKkkZEfQy52kPFfHLZgcZ2JMFo2iQ0DqRcq7nqwnU1JRbNTHEQ56WOsStWn7IGfBqA43B5QdLn-yWTiP5AIalG3kv_o-6VZTmyfu6QbBCbwD_7gpjewoB8IiYn86WaTVbvkryGBJZMjSEq5M2H1m365zI392lNZVzwDADwF04s4zYmHx8snkk9Z3NUAjvzDJo9b1IJNNIKnPmERysOR73W_hAfZdpVN0Ltx2fT7-13g4ow-2Xizi_t2b4SQcX6tC_tlju224eh0KkKNxOJ3irBQRsWAT9iKe_aaE7usFUkZgfR9vuZnPO62qzuxUwROsX3-Tz4lSxSD2N4ajqpEpVMcS528hMO5lXQwMA2RpGBKpR2JJzsN1KdbYgPcB16Ad14VgJNJ 产地:https://开头本地主机:44390 引荐:https:// localhost:44390 / Home / EditProject / 66 upgrade-insecure-requests:1 user-agent:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML ,例如Gecko)Chrome / 75.0.3770.100 Safari / 537.36 ---------------------------------------------- -------------------------------------------------- --- 表单数据:标题:产品工程师描述:nulla neque libero convallis eget eleifend 内容:sodales scelerisque mauris sit amet erossuspisse accumsan tortor quis turpis s ante ante vivamus斗牛士Mattis egestas metus aenean发酵罐doc ut mauris eget massa tempor convallis nulla neque libero convallis eget eleifend luctus ultricies eu nibh quisque id justo sit amet sapien dignissimvesivelum结束了一场恶性争斗,并最终获得了胜利,并最终获得了胜任权。 Project_Image:http://dummyimage.com/193x141.jpg/ff4444/ffffff Live_Url: .com / eget / tincidunt / eget.jpg Github_Repo:sourceforge.net/et/ultrices/posuere/cubilia.jpg Bitbucket_Repo:creativecommons.org/pede/libero/quis.html 创建:2011-07-11T00:00:00.000 更新:2019-06-20T00:00:00.000 __RequestVerificationToken: CfDJ8OfA6sTjcU1PuqxxzGM-oMq4kGmbGOLj875J5O8hQlwLIYQR7YHYe58lgzEyN5Wat3viIjRuF80IPiwf_iRYUydAC0vfWv-q5jvLA_bAsdz7blAbvNoT4TxTYqZ5ONf5Q2bYqOyWlhdoN7ZduEaRc3dEBua_8F35F6mNuq0NFfLTDkvlCvO1da4dbhsWg49nsg ----------------------------------------- -------------------------------------------------- -------- 故障(评论) 常规:请求网址:https:// localhost:44390 / Home / EditComment / 20 请求方法:POST 状态码:500 远程地址:[:: 1]:44390 推荐人政策:no-referrer-何时降级 ------------------------------------------- -------------------------------------------------- ------ 响应标题:内容类型:text / h tml; charset = utf-8 日期:2019年6月30日,星期日23:40:23 GMT 服务器:Kestrel 状态:500 x技术支持:ASP.NET x-sourcefiles:=?UTF-8?B?QzpcV29ya3NwYWNlXHd3d1xhc3BcUG9ydGZvbGlvXFBvcnRmb2xpb1xIb21lXEVkaXRDb21tZW50XDIw?= ---------------------------- -------------------------------------------------- --------------------- 请求标头::authority:localhost:44390 :方法:POST :path:/ Home / EditComment / 20 :scheme:https accept:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng,* /*;q=0.8,application/signed-exchange;v=b3 accept-encoding:gzip,deflate,br accept-language:en-US,en; q = 0.9,mt; q = 0.8 缓存控制:最大年龄= 0 内容长度:558 内容类型:application / x-www-form-urlencoded cookie:.AspNetCore。 Antiforgery.x5eNnYCJ5UA = CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ 1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application = CfDJ8OfA6sTjcU1PuqxxzGM-oMpTJYFjUyUy3eLO3fbnX9V4SSq14P_h_AlTAyZs-9LrMW9QOzTP46d8CJetHqzamw-ulm6IbjGyC_hElFiwtJRbKAV3GuVlGQeNfbhcJ7M81EH4bqnbi-NBwP4nmlXROTG3DvMYdHqC1-eqT53ip4mnHpdLDLKlwX80Lk8uWPpiyD5L_RFiMGl5i0vOUz19bbn-mSC3IVbuGz8LeDePfKDmU-3b8_sNiZJpBpx4p6jORrds69LkpkdZX2NUWzyevM4TWw8irVRRBY0PAFKkkZEfQy52kPFfHLZgcZ2JMFo2iQ0DqRcq7nqwnU1JRbNTHEQ56WOsStWn7IGfBqA43B5QdLn-yWTiP5AIalG3kv_o-6VZTmyfu6QbBCbwD_7gpjewoB8IiYn86WaTVbvkryGBJZMjSEq5M2H1m365zI392lNZVzwDADwF04s4zYmHx8snkk9Z3NUAjvzDJo9b1IJNNIKnPmERysOR73W_hAfZdpVN0Ltx2fT7-13g4ow-2Xizi_t2b4SQcX6tC_tlju224eh0KkKNxOJ3irBQRsWAT9iKe_aaE7usFUkZgfR9vuZnPO62qzuxUwROsX3-Tz4lSxSD2N4ajqpEpVMcS528hMO5lXQwMA2RpGBKpR2JJzsN1KdbYgPcB16Ad14VgJNJ 产地:https://开头本地主机:44390 引荐:https:// localhost:44390 / Home / EditComment / 20 upgrade-insecure-requests:1 user-agent:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML ,例如Gecko)Chrome / 75.0.3770.100 Safari / 537.36 ---------------------------------------------- -------------------------------------------------- --- 表单数据: Mp_Post_Id:20 Mp_Guest_Id:20 评论:etiam faucibus cursus urna uttellus nulla ut eartt id mauris vulputate elementum nullam varius nulla 业力:6 批准:0 Ip:142.146.130.50 代理:Mozilla / 5.0(Windows NT 5.1; rv:14.0)Gecko / 20120405 Firefox / 14.0a1 创建:2010-10-21T00:00:00.000 更新:2009-10-07T00:00:00.000 __RequestVerificationToken:CfDJ8OfA6sTjcU1PuqxxzGM-oMpEiWlpyDJJHiDaw7Rz0PI -L3LvBS94t5QxvcBZ2PwMUI9McLlFR1rtds9yh89UZSzHpR-q_SvbM1g4KCUYDhvNht_bMaoy9NJvMTfOCR_TPW4CKTMnJCR8OEJYahY9CWXY_GozMl1MMkL -------- -------------------------------------------------- ------- Wireshark(流量分析) 成功(编辑项目) POST / Home / EditProject / 2 HTTP / 1.1 缓存控制:max-age = 0 连接:保持活动内容类型:application / x-www-form-urlencoded 接受:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng,* / *; q = 0.8,application / signed-exchange; v = b3 Accept-Encoding:gzip,deflate,br Accept-Lan瓜哥:EN-US,EN; Q = 0.9,MT; Q = 0.8 曲奇:.AspNetCore.Antiforgery.x5eNnYCJ5UA = CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application = CfDJ8OfA6sTjcU1PuqxxzGM-oMqPm6KX-2uhTXr62WeE6Jia-lF8RtuWQCtjegxTJyf6k-wmUcVdvsBAhEuLKWMN_ttD6dPUr-E8QGJPI_2fD0vYnbo6ADWRXWlMFHwloQ43bPBuSn0zPyp6rZvQLaYFXQXO2aO9Kk7UF64Nh4-kJenvCOcPYtv5JS5HneYXgXO_hM26wnG-3my6SaA4ApdBYndK4DbrdB4393HtLK1579yg7ON12bDIBH71pTMdK6UuIvAI1Bh3HbkUuCOtJzZ3ZqB_JQAutgRe6z6nFGcdPMcb0VbIUPa9USyg0oUJ9KxNPspX9y_dAt4GO18OrsFd-S8D-oWV7zDEMpQVBpLoaVk23xpiObUlVLfS-OQhfVgq3RAXAfkZOR7B7eusFkr3I_ZQRb__76x8dVRvHDy-gy_2ZU1xNJve0v-L38kRsVKoXpjCfc9HW9CaVZvoOH6YB1x-gwsGB_eJ8IJsMTnscrNhDloNlel42K7q8GlA-lTK9yXgiXqLm2VAYdpCf_b45ixMba0Cr7umLyMBzf7BEo3J5uNEAYvF7qN5DOlTSbuvwP33ZbBQJyu3uwnfi4JdzYHNDtlZJqlgUkVgmw_3snp3oJxizU50DFgTUyPjAuB71aEOEyVQRXbgZbJ_S-TzLddHc-hjZarUqKK6n5MBX-8_1 主机:本地主机: 44390 引用者:https:// localhost:44390 / Home / EditProject / 2 用户代理:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,like Gecko)Chrome /75.0.3770.100 Safari / 537.36 来源:https:// localhost:44390 upgrade-insecure-re任务:1 MS-ASPNETCORE-TOKEN:2a6aebc6-e154-4f02-9517-cae788a1069f X-Forwarded-For:[:: 1]:60639 X-Forwarded-Proto:https 内容长度:710 标题=高级+质量+工程师+ IV& Desc = nascetur + ridiculus + mus + vivamus + vestibulum + sagittis + sapien + cum + sociis& Content = vivamus + tortor + duis + mattis + egestas + metus + aenean + fermentum + donec + ut + mauris + eget& Project_Image = http%3A%2F%2Fdummyimage.com%2F237x180.bmp%2F5fa2dd%2Fffffff& Live_Url = ihg.com%2F %2Fnisi%2Fat%2Fnibh.json& Github_Repo = paginegialle.it%2Fligula%2Fsuspendisse.xml& Bitbucket_Repo = harvard.edu%2Fcongue.aspx& Create = 2018-09-07T00%3A00%3A00.000& Update = 2013 -17T00%3A00%3A00.000&安培; __ RequestVerificationToken = CfDJ8OfA6sTjcU1PuqxxzGM-oMqFkSNAgkReKvXjTW0EStR_OB4Zz6j90ZdieDNspaE86824rUys1Av2cI9mKtO15RaMnYSiz1_As63Ez0XWxX4N3zfL4vlgGfPQ43FMqqfcPBAG33xvi4G0naOTHEVTdGbiwkLrK2UVF2O01JzfVW3olYbxna45Pg10haFTI-s5QgHTTP / 1.1 302实测值日期:星期一,2019年7月1日16时19分16秒GMT 服务器:茶隼内容长度:0 位置:/ Home / ViewProjects 失败(编辑评论) POST / Home / EditComment / 1 HTTP / 1.1 缓存控制:max-age = 0 连接:保持活动状态内容类型:application / x-www-form-urlencoded 接受:text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng,* / *; q = 0.8,application / signed-exchange; v = b3 接受编码:gzip,放气,BR 接受语言:EN-US,EN; q = 0.9,MT; q = 0.8 曲奇:.AspNetCore.Antiforgery.x5eNnYCJ5UA = CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application = CfDJ8OfA6sTjcU1PuqxxzGM-oMqsILl7uDq3qp0MgEGexCwq_b2cNi4376Wt5jxWgINpwDxVRedde5wkOvqycIGfKrQJM2uCVgFMc75i-3Ch_Sct3wFtj_o2wHjLt9OSgM1dieKWdY8BVsLWGHIsMkceMbh_GQz6xJsKrOixjijHUw88p990DPKm2dGJo-JLSHJpqxGNkQxlhPNPf-VsHEQmh27Mn2ah_NZj0NqIlxDuxfmeLQoV0W1s99zVg7URMUbSmGQsShrT1HxhcUjesLuGnyy90GdxmFyGf2-RKPl1zGdkQhaIgicmxQi-bR8otlu5E1uHPms-_HR3xZwT3koowKFYNM4NFHfPuQOwPgZooHCJeaYvweHuqiB5Oh98c6gRHalMSUqGApIICOfVY7mrr9uxt70PeB60PisyAfASCClKf0IsnJLh8flRZ5lr7cr4fhVXU9Jn-PS_09-iX262WvSgjWiPvfe6W_3QxhnPV1NBb0xVy7FCBNMeIIge0BftQzGMb0h_2xsCITwf9oAApXH-uTnC4E2FZI1nUzdfRVPCrj0kXsppeVr6q-65d9_cWgh2aDC4EYeCF4v__Yz9IZPoMKCvHF_rq_Vna4jLPLsobt4VcViYrSY66JmtO9IeoXpA3Ivd2P7ws4lcnJ9STgFV4oP3hmC4aRdA1BURRzz2 主机:本地主机:44390 的Referer:https://开头本地主机:44390 / Home / EditComment / 1 用户代理:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 75.0.3770.100 Safari / 537.36 来源:https:// localhost:44390 upgrade-insecure-re任务:1 MS-ASPNETCORE-TOKEN:2a6aebc6-e154-4f02-9517-cae788a1069f X-Forwarded-For:[:: 1]:61219 X-Forwarded-Proto:https 内容长度:606 Mp_Post_Id = 1& Mp_Guest_Id = 1& Comment = lorem + quisque + ut + erat + curabitur + gravida + nisi + at + nibh + in + hac + habitasse + platea + dictumst + aliquam& Karma = 1&已批准= 1& Ip = 21.99.31.96& Agent = Mozilla%2F5.0 +%28Macintosh%3B + U%3B + Intel + Mac + OS + X + 10_7%3B + zh-TW%29 + AppleWebKit%2F533.4 +%28KHTML%2C + like + Gecko%29 + Version%2F4.1 + Safari%2F533.4& Create = 2018-07-17T00%3A00%3A00.000&更新= 2012-06-01T00%3A00%3A00.000和放大器; __ RequestVerificationToken = CfDJ8OfA6sTjcU1PuqxxzGM-oMr9nzkkEn5p6n7jwRflZ1bmxhEOVzWiW7VXO1rmDYbHQR4CvYlmqH4LyuHMPDsQZWXE-gZ3eDU2LWqJd1uVnMKeJcbV0gne1gxSQdeg2Cd7wklVGIJAlC4PNr5hbqJmAGItiemNRukLVKMLVZ0E65dR-pVhxKy4SteMmvnDVMg5_QHTTP / 1.1 500内部服务器错误日期:星期一,2019年7月1日17时06分52秒GMT 内容类型:text / html; charset = utf-8 服务器:Kestrel 传输编码:块状 附加信息 项目配置 myProject.csproj < Project Sdk = Microsoft.NET.Sdk.Web> < PropertyGroup> < TargetFramework> netcoreapp2.1< / TargetFramework> < / PropertyGroup> < ItemGroup> < PackageReference Include = Microsoft.AspNetCore.App Version = 2.1.2 /> < PackageReference Include = Microsoft.AspNetCore.Razor.Design Version = 2.1.2 PrivateAssets = All /> < PackageReference Include = Microsoft.VisualStudio.Web.CodeGeneration.Design Version = 2.1.9 /> < PackageReference Include = MySql.data Version = 8.0.16 /> < PackageReference Include = MySql.Data.EntityFrameworkCore Version = 8.0.16 /> < / ItemGroup> < ItemGroup> < Folder Include = Migrations\ /> < / ItemGroup> < / Project> 数据库 [mpComment.sql] 创建表[mpComment] ( [id] INT非空主键, [mp_post_id] INT非空外键引用mpPost(id), [mp_guest_id ] INT NOT NULL外国关键字引用mpGuest(id), [注释] NVARCHAR(500)NOT NULL, [karma] INT NULL, [已批准] INT NOT NULL, [ip] NVARCHAR(100)NULL, [代理] NVARCHAR(255)NULL, [创建] DATETIME NULL, [update] DATETIME NULL,) 插入查询 CommentsInsertQuery。 sql 完全相同与通过上述表格提交的数据相同(通常); 插入[profileDb]。[ dbo]。[mpComment]([mp_post_id],[mp_guest_id],[comment],[karma],[approved],[ip],[agent],[create],[update])值(1 ,1、1,'在习惯性居留权的碟状aliquam的笔尖处','1,','21.99.31.96','Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10_7; en-us) AppleWebKit / 533.4(KHTML,like Gecko)Version / 4.1 Safari / 533.4','07 / 17/2018','06 / 01/2012'); 最后的想法 我担心此问题可能发生在实体框架内的某个地方,我无法进行故障排除。如果我有一个真诚的起点,可以确定.Net框架捕获浏览器数据的确切点,那么我也许可以更好地确定关键问题。 类似帖子: a> 这个问题与另一个问题非常相似,但是,故障排除似乎少了很多,有关物。此外,在这个问题上没有多大兴趣,也没有提供解决方案。 感谢进步和欢呼解决方案 Jerry Rigged解决方案 我能够为了管理变通办法,尽管如此,我仍然不确定出现此错误的原因。 简介 感觉到回发数据已在应用程序中捕获(图形),但是,它没有填充 EditComments 方法的参数值,我只是手动填充了数据。 解决方案 包含 Microsoft.AspNetCore.Http 我的Home Controller中的库,并修改了以下回发方法: HomeController.cs [HttpPost] 公共异步任务< IActionResult> EditComment(MpComment评论) { comment.Id = 0; _repo.AddComment(comment); if(await _repo.SaveChangesAsync()) return RedirectToAction( ViewComments); else return View(comment); } 至 HomeController.cs [HttpPost] 公共异步任务< IActionResult> EditComment() { var form = Request.Form.ToList(); var comment = new MpComment { Id = 0, Mp_Post_Id = Int32.Parse(form.Where(x => x.Key == Mp_Post_Id)。FirstOrDefault()。Value), Mp_Guest_Id = Int32.Parse(form.Where(x => x.Key == Mp_Guest_Id)。FirstOrDefault()。Value),注释= form.Where(x => x.Key ==注释).FirstOrDefault()。Value, Karma = Int32.Parse(form.Where(x => x.Key == Karma)。FirstOrDefault()。Value),批准= Int32.Parse(form.Where(x => x.Key == Approved)。FirstOrDefault()。Value), Ip = form.Where(x => x.Key == Ip)。FirstOrDefault()。Value, Agent = form.Where(x => x.Key == Agent)。 FirstOrDefault()。Value, Create = Convert.ToDateTime(form.Where(x => x.Key == Create)。FirstOrDefault()。Value), Update = Convert.ToDateTime (form.Where(x => x.Key == \"Upd ate\").FirstOrDefault().Value) }; _repo.AddComment(comment); if (await _repo.SaveChangesAsync()) return RedirectToAction(\"ViewComments\"); else return View(comment); } ...and everything works as expected. Additional note These values were easy enough to retrieve, in case anyone else has a similar issue. Simply convert the request form data into a List (as above) and print out those results via the output console. Example: [HttpPost] public methodExpectingPostback() { var form = Request.Form.ToList(); foreach (var item in form) { Debug.WriteLine($\"{item.Key} : {item.Value}\"); } } ScenarioI'm setting up a blog and am configuring a page to POST edited comments to an MsSql server.IssueAfter I submit submit a form POST, via my view, the property values that are supposed to be captured and returned via this form, are all returned as "NULL"!? This eventually causes an exception error due to there being NULL values present within my data model. After stepping through my entire application, and using Fiddler, I am unable to diagnose the issue.Quick Visual Example After a POST has been submitted (during run-time) and my application has reached the Home Controller of my blog, this is what's shown and available.Captured Form Data - Seen through Visual Studio's local inspectorPOST data received in Home ControllerNote: as you can see, each input's value is captured by the Home Controller during run-time. However, this data is not transferred to the EditComment method post POST.ProcessInput controls are populated with property values for my model, then submitted: EditComments.cs @model MpComment ... HTML Content ... <form asp-controller="Home" asp-action="EditComment" method="post" class="text-danger input-form"> <div asp-validation-summary="ModelOnly"></div> <div class="form-group"> <label asp-for="<Model.Property>" class="control-label"></label> <input asp-for="<Model.Property>" class="form-control" /> <span asp-validation-for="<Model.Property>" class="text-danger"></span> </div> ... ASP Form Input Elements... <div class="form-group input-submit"> <input type="submit" value="Submit" class="btn material-button" /> </div> </form>My AppDbContext is initialized AppDbContext.csnamespace Portfolio.Data{ public class AppDbContext : IdentityDbContext { public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { } public virtual DbSet<MpPost> MpPost { get; set; } public virtual DbSet<MpComment> MpComment { get; set; } public virtual DbSet<MpGuest> MpGuest { get; set; } public virtual DbSet<MpLogin> MpLogin { get; set; } public virtual DbSet<MpProject> MpProject { get; set; } }}My MpComments model begins to appear to move through and set each properties value, however, the data that populates each property is NULL. using System; using System.ComponentModel.DataAnnotations; namespace Portfolio.Models { public partial class MpComment { public int Id { get; set; } public int Mp_Post_Id { get; set; } public int Mp_Guest_Id { get; set; } public string Comment { get; set; } public int? Karma { get; set; } public int? Approved { get; set; } public string Ip { get; set; } public string Agent { get; set; } public DateTime? Create { get; set; } = DateTime.Now; public DateTime? Update { get; set; } = DateTime.Now; } }Once nothing gets populated, the Home Controller is initiated, and the following function is called: HomeController.cs [HttpPost] public async Task<IActionResult> EditComment(MpComment comment) { comment.Id = 0; _repo.AddComment(comment); if (await _repo.SaveChangesAsync()) return RedirectToAction("ViewComments"); else return View(comment); }It's at this point where the comment parameter variable populated from the POST contains only NULL values, and appears like so:Investigation & AnalysisVisualStudioLocal Variable Inspector Agent null Approved null Comment null Create {6/30/2019 1:04:29 PM} Id 0 Ip null Karma null Mp_Guest_Id 0 Mp_Post_Id 0 Update {6/30/2019 1:04:29 PM}This procedure works as expected on other procedures set to accomplish this exact same feature, just on a different table!?For example, here's what Fiddler captured on a successful POST, from an almost identical POST'ing procedure:Fiddler InspectorRaw (Success for EditProject) POST https://localhost:44390/Home/EditProject/21 HTTP/1.1 Host: localhost:44390 Connection: keep-alive Content-Length: 555 Cache-Control: max-age=0 Origin: https://localhost:44390 Upgrade-Insecure-Requests: 1 Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 Referer: https://localhost:44390/Home/EditProject/21 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,mt;q=0.8 Cookie: .AspNetCore.Antiforgery.x5eNnYCJ5UA=CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application=CfDJ8OfA6sTjcU1PuqxxzGM-oMp2YqORrHzf5IL0rLJ8jvAP-RYvHIXeH63EfD3-TugdZGBP9nf_lHhAn71ACsIQZe_cJ1x7u3FBh25uhlXZIJX9yk7ZdH_GuwfYEe-Zaa1CSAD2f2g8U7syt8jvxy18c-qCN9Yq2zLQpBeOlzftudcaMKKrsA-UGO8BOHLPTk1TYe1QMosDGaFDLXY0POqCpluxiiA0qsA0i9iQeAP6HL7ZC8lLjf76Lf_E5usVyakwa9X3ELDJQeaEFFa5Vi_5063xCHhm3NRREE5loUCff1rKmaOKvvOR-Fnf-QtYLG-MGthgVAGah4cdXjD0jsKFBM0Ny-Yt8uRddQ26w_8AUJqhRo9jOAXEuzyhYwPRfKQKykgpy-4lVIZXc2QR25EWxq9H6zh5GGCTIitxISDcpoHf0mUqzT9aJKo_LwB6cibzbDwBmVsTc6Yn6cQA0MMoBVa6E6hKuvQoNerU7psX5z2D2k8tB8mZVlJQ3medeMwHQonOSBh99OxOrBO5K6iedlpPqSNco8r7PbNcHCdhLKehtoyJkE3tzmrv_EOTAS7ldXNhhPHqNp_RmuAdGWlsJ-a-bN5itj1hv_o7RCxl8t49XB9oddsg4iOvR-BUZOLuxJKfQ90PAH4S9BvblwLKoXx3Gt3We5WeG8Ga6rAXHQhd Id=0&Title=Product+Engineer&Desc=nulla+neque+libero+convallis+eget+eleifend&Live_Url=bloglovin.com%2Feget%2Ftincidunt%2Feget.jpg&Github_Repo=sourceforge.net%2Fet%2Fultrices%2Fposuere%2Fcubilia.jpg&Bitbucket_Repo=creativecommons.org%2Fpede%2Flibero%2Fquis.html&Create=2011-07-11T00%3A00%3A00.000&Update=2019-06-20T00%3A00%3A00.000&__RequestVerificationToken=CfDJ8OfA6sTjcU1PuqxxzGM-oMqTHmlRblU70EY0Ou7tH2IifiXdJOCtMRepfMg-GhKz-j4at6h9BOzJTNjHIROMjDpUiOqxvDeGWcja8K-uGkYrW8DX58j9mIFlwKML9tLVtvusmGmPekVMPxYqRkKdcyLGb6qpav3upDLAvfxLblbs9RynCyG4bDTAAZ4jzxc-wwFiddler InspectorRaw (Failure for EditComments) POST https://localhost:44390/Home/EditComment/1 HTTP/1.1 Host: localhost:44390 Connection: keep-alive Content-Length: 606 Cache-Control: max-age=0 Origin: https://localhost:44390 Upgrade-Insecure-Requests: 1 Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 Referer: https://localhost:44390/Home/EditComment/1 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9,mt;q=0.8 Cookie: .AspNetCore.Antiforgery.x5eNnYCJ5UA=CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application=CfDJ8OfA6sTjcU1PuqxxzGM-oMp2YqORrHzf5IL0rLJ8jvAP-RYvHIXeH63EfD3-TugdZGBP9nf_lHhAn71ACsIQZe_cJ1x7u3FBh25uhlXZIJX9yk7ZdH_GuwfYEe-Zaa1CSAD2f2g8U7syt8jvxy18c-qCN9Yq2zLQpBeOlzftudcaMKKrsA-UGO8BOHLPTk1TYe1QMosDGaFDLXY0POqCpluxiiA0qsA0i9iQeAP6HL7ZC8lLjf76Lf_E5usVyakwa9X3ELDJQeaEFFa5Vi_5063xCHhm3NRREE5loUCff1rKmaOKvvOR-Fnf-QtYLG-MGthgVAGah4cdXjD0jsKFBM0Ny-Yt8uRddQ26w_8AUJqhRo9jOAXEuzyhYwPRfKQKykgpy-4lVIZXc2QR25EWxq9H6zh5GGCTIitxISDcpoHf0mUqzT9aJKo_LwB6cibzbDwBmVsTc6Yn6cQA0MMoBVa6E6hKuvQoNerU7psX5z2D2k8tB8mZVlJQ3medeMwHQonOSBh99OxOrBO5K6iedlpPqSNco8r7PbNcHCdhLKehtoyJkE3tzmrv_EOTAS7ldXNhhPHqNp_RmuAdGWlsJ-a-bN5itj1hv_o7RCxl8t49XB9oddsg4iOvR-BUZOLuxJKfQ90PAH4S9BvblwLKoXx3Gt3We5WeG8Ga6rAXHQhd Mp_Post_Id=1&Mp_Guest_Id=1&Comment=lorem+quisque+ut+erat+curabitur+gravida+nisi+at+nibh+in+hac+habitasse+platea+dictumst+aliquam&Karma=1&Approved=1&Ip=21.99.31.96&Agent=Mozilla%2F5.0+%28Macintosh%3B+U%3B+Intel+Mac+OS+X+10_7%3B+en-us%29+AppleWebKit%2F533.4+%28KHTML%2C+like+Gecko%29+Version%2F4.1+Safari%2F533.4&Create=2018-07-17T00%3A00%3A00.000&Update=2012-06-01T00%3A00%3A00.000&__RequestVerificationToken=CfDJ8OfA6sTjcU1PuqxxzGM-oMquggjJDBhMvQwfCKwHRJS9tJeBi-4bT19jJVjuUjZgYE1LD4BvCF2LBJlQ45u3d9sEGmm-l9EAhbXaA2TwuNjW4xhYpVXl4Z0YE_YBEvbuSzodxjP8v1GoYAXYfs5yl3L39SK0gp1YKkkwujMhdExO17v3n-b_y4IhhZJ3SanIZwNote: Everything appears identical (where it should), except there's a discrepancy with the POST URL. Each time I troubleshoot this, I take the 1st entry, edit it, and then submit it. Each time I do this (on the four other procedures where this works fine), it iterates to the next entry; as seen above.Example: A) Edit & Submit Project 1 when there's 20 Project entries:POST https://localhost:44390/Home/EditProject/21 <=== discrepancyB) Edit & Submit Comment 1 when there's 20 Comment entries:POST https://localhost:44390/Home/EditComment/1 <=== discrepancyChrome (Network Headers) Success (Project)General: Request URL: https://localhost:44390/Home/EditProject/66 Request Method: POST Status Code: 302 Remote Address: [::1]:44390 Referrer Policy: no-referrer-when-downgrade---------------------------------------------------------------------------------------------------Response Headers: content-length: 0 date: Mon, 01 Jul 2019 00:04:16 GMT location: /Home/ViewProjects server: Kestrel status: 302 x-powered-by: ASP.NET x-sourcefiles: =?UTF-8?B?QzpcV29ya3NwYWNlXHd3d1xhc3BcUG9ydGZvbGlvXFBvcnRmb2xpb1xIb21lXEVkaXRQcm9qZWN0XDY2?=---------------------------------------------------------------------------------------------------Request Headers: :authority: localhost:44390 :method: POST :path: /Home/EditProject/66 :scheme: https accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9,mt;q=0.8 cache-control: max-age=0 content-length: 1200 content-type: application/x-www-form-urlencoded cookie: .AspNetCore.Antiforgery.x5eNnYCJ5UA=CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application=CfDJ8OfA6sTjcU1PuqxxzGM-oMpTJYFjUyUy3eLO3fbnX9V4SSq14P_h_AlTAyZs-9LrMW9QOzTP46d8CJetHqzamw-ulm6IbjGyC_hElFiwtJRbKAV3GuVlGQeNfbhcJ7M81EH4bqnbi-NBwP4nmlXROTG3DvMYdHqC1-eqT53ip4mnHpdLDLKlwX80Lk8uWPpiyD5L_RFiMGl5i0vOUz19bbn-mSC3IVbuGz8LeDePfKDmU-3b8_sNiZJpBpx4p6jORrds69LkpkdZX2NUWzyevM4TWw8irVRRBY0PAFKkkZEfQy52kPFfHLZgcZ2JMFo2iQ0DqRcq7nqwnU1JRbNTHEQ56WOsStWn7IGfBqA43B5QdLn-yWTiP5AIalG3kv_o-6VZTmyfu6QbBCbwD_7gpjewoB8IiYn86WaTVbvkryGBJZMjSEq5M2H1m365zI392lNZVzwDADwF04s4zYmHx8snkk9Z3NUAjvzDJo9b1IJNNIKnPmERysOR73W_hAfZdpVN0Ltx2fT7-13g4ow-2Xizi_t2b4SQcX6tC_tlju224eh0KkKNxOJ3irBQRsWAT9iKe_aaE7usFUkZgfR9vuZnPO62qzuxUwROsX3-Tz4lSxSD2N4ajqpEpVMcS528hMO5lXQwMA2RpGBKpR2JJzsN1KdbYgPcB16Ad14VgJNJ origin: https://localhost:44390 referer: https://localhost:44390/Home/EditProject/66 upgrade-insecure-requests: 1 user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36---------------------------------------------------------------------------------------------------Form Data: Title: Product Engineer Desc: nulla neque libero convallis eget eleifend Content: sodales scelerisque mauris sit amet eros suspendisse accumsan tortor quis turpis sed ante vivamus tortor duis mattis egestas metus aenean fermentum donec ut mauris eget massa tempor convallis nulla neque libero convallis eget eleifend luctus ultricies eu nibh quisque id justo sit amet sapien dignissim vestibulum vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae nulla dapibus dolor vel est donec odio justo sollicitudin ut suscipit a feugiat et eros vestibulum ac est lacinia nisi venenatis tristique fusce congue diam id ornare Project_Image: http://dummyimage.com/193x141.jpg/ff4444/ffffff Live_Url: bloglovin.com/eget/tincidunt/eget.jpg Github_Repo: sourceforge.net/et/ultrices/posuere/cubilia.jpg Bitbucket_Repo: creativecommons.org/pede/libero/quis.html Create: 2011-07-11T00:00:00.000 Update: 2019-06-20T00:00:00.000 __RequestVerificationToken: CfDJ8OfA6sTjcU1PuqxxzGM-oMq4kGmbGOLj875J5O8hQlwLIYQR7YHYe58lgzEyN5Wat3viIjRuF80IPiwf_iRYUydAC0vfWv-q5jvLA_bAsdz7blAbvNoT4TxTYqZ5ONf5Q2bYqOyWlhdoN7ZduEaRc3dEBua_8F35F6mNuq0NFfLTDkvlCvO1da4dbhsWg49nsg--------------------------------------------------------------------------------------------------- Failure (Comment)General: Request URL: https://localhost:44390/Home/EditComment/20 Request Method: POST Status Code: 500 Remote Address: [::1]:44390 Referrer Policy: no-referrer-when-downgrade---------------------------------------------------------------------------------------------------Response Headers: content-type: text/html; charset=utf-8 date: Sun, 30 Jun 2019 23:40:23 GMT server: Kestrel status: 500 x-powered-by: ASP.NET x-sourcefiles: =?UTF-8?B?QzpcV29ya3NwYWNlXHd3d1xhc3BcUG9ydGZvbGlvXFBvcnRmb2xpb1xIb21lXEVkaXRDb21tZW50XDIw?=---------------------------------------------------------------------------------------------------Request Headers: :authority: localhost:44390 :method: POST :path: /Home/EditComment/20 :scheme: https accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3 accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9,mt;q=0.8 cache-control: max-age=0 content-length: 558 content-type: application/x-www-form-urlencoded cookie: .AspNetCore.Antiforgery.x5eNnYCJ5UA=CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application=CfDJ8OfA6sTjcU1PuqxxzGM-oMpTJYFjUyUy3eLO3fbnX9V4SSq14P_h_AlTAyZs-9LrMW9QOzTP46d8CJetHqzamw-ulm6IbjGyC_hElFiwtJRbKAV3GuVlGQeNfbhcJ7M81EH4bqnbi-NBwP4nmlXROTG3DvMYdHqC1-eqT53ip4mnHpdLDLKlwX80Lk8uWPpiyD5L_RFiMGl5i0vOUz19bbn-mSC3IVbuGz8LeDePfKDmU-3b8_sNiZJpBpx4p6jORrds69LkpkdZX2NUWzyevM4TWw8irVRRBY0PAFKkkZEfQy52kPFfHLZgcZ2JMFo2iQ0DqRcq7nqwnU1JRbNTHEQ56WOsStWn7IGfBqA43B5QdLn-yWTiP5AIalG3kv_o-6VZTmyfu6QbBCbwD_7gpjewoB8IiYn86WaTVbvkryGBJZMjSEq5M2H1m365zI392lNZVzwDADwF04s4zYmHx8snkk9Z3NUAjvzDJo9b1IJNNIKnPmERysOR73W_hAfZdpVN0Ltx2fT7-13g4ow-2Xizi_t2b4SQcX6tC_tlju224eh0KkKNxOJ3irBQRsWAT9iKe_aaE7usFUkZgfR9vuZnPO62qzuxUwROsX3-Tz4lSxSD2N4ajqpEpVMcS528hMO5lXQwMA2RpGBKpR2JJzsN1KdbYgPcB16Ad14VgJNJ origin: https://localhost:44390 referer: https://localhost:44390/Home/EditComment/20 upgrade-insecure-requests: 1 user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36---------------------------------------------------------------------------------------------------Form Data: Mp_Post_Id: 20 Mp_Guest_Id: 20 Comment: etiam faucibus cursus urna ut tellus nulla ut erat id mauris vulputate elementum nullam varius nulla Karma: 6 Approved: 0 Ip: 142.146.130.50 Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120405 Firefox/14.0a1 Create: 2010-10-21T00:00:00.000 Update: 2009-10-07T00:00:00.000 __RequestVerificationToken: CfDJ8OfA6sTjcU1PuqxxzGM-oMpEiWlpyDJHiDaw7Rz0PI6fyiscJ9aAahlk0J2Coz5R42uB-L3LvBS94t5QxvcBZ2PwMUI9McLlFR1rtds9yh89UZSzHpR-q_SvbM1g4KCUYDhvNht_bMaoy9NJvMTfOCR_TPW4CKTMnJCR8OEJYahY9CWXY_GozMl1MMkL3MFkFQ---------------------------------------------------------------------------------------------------Wireshark (Traffic Analysis) Success (Edit Project)POST /Home/EditProject/2 HTTP/1.1Cache-Control: max-age=0Connection: Keep-AliveContent-Type: application/x-www-form-urlencodedAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3Accept-Encoding: gzip, deflate, brAccept-Language: en-US,en;q=0.9,mt;q=0.8Cookie: .AspNetCore.Antiforgery.x5eNnYCJ5UA=CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application=CfDJ8OfA6sTjcU1PuqxxzGM-oMqPm6KX-2uhTXr62WeE6Jia-lF8RtuWQCtjegxTJyf6k-wmUcVdvsBAhEuLKWMN_ttD6dPUr-E8QGJPI_2fD0vYnbo6ADWRXWlMFHwloQ43bPBuSn0zPyp6rZvQLaYFXQXO2aO9Kk7UF64Nh4-kJenvCOcPYtv5JS5HneYXgXO_hM26wnG-3my6SaA4ApdBYndK4DbrdB4393HtLK1579yg7ON12bDIBH71pTMdK6UuIvAI1Bh3HbkUuCOtJzZ3ZqB_JQAutgRe6z6nFGcdPMcb0VbIUPa9USyg0oUJ9KxNPspX9y_dAt4GO18OrsFd-s8d-oWV7zDEMpQVBpLoaVk23xpiObUlVLfS-OQhfVgq3RAXAfkZOR7B7eusFkr3I_ZQRb__76x8dVRvHDy-gy_2ZU1xNJve0v-L38kRsVKoXpjCfc9HW9CaVZvoOH6YB1x-gwsGB_eJ8IJsMTnscrNhDloNlel42K7q8GlA-lTK9yXgiXqLm2VAYdpCf_b45ixMba0Cr7umLyMBzf7BEo3J5uNEAYvF7qN5DOlTSbuvwP33ZbBQJyu3uwnfi4JdzYHNDtlZJqlgUkVgmw_3snp3oJxizU50DFgTUyPjAuB71aEOEyVQRXbgZbJ_S-TzLddHc-hjZarUqKK6n5MBX-8_Host: localhost:44390Referer: https://localhost:44390/Home/EditProject/2User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36origin: https://localhost:44390upgrade-insecure-requests: 1MS-ASPNETCORE-TOKEN: 2a6aebc6-e154-4f02-9517-cae788a1069fX-Forwarded-For: [::1]:60639X-Forwarded-Proto: httpsContent-Length: 710Title=Senior+Quality+Engineer+IV&Desc=nascetur+ridiculus+mus+vivamus+vestibulum+sagittis+sapien+cum+sociis&Content=vivamus+tortor+duis+mattis+egestas+metus+aenean+fermentum+donec+ut+mauris+eget&Project_Image=http%3A%2F%2Fdummyimage.com%2F237x180.bmp%2F5fa2dd%2Fffffff&Live_Url=ihg.com%2Fgravida%2Fnisi%2Fat%2Fnibh.json&Github_Repo=paginegialle.it%2Fligula%2Fsuspendisse.xml&Bitbucket_Repo=harvard.edu%2Fcongue.aspx&Create=2018-09-07T00%3A00%3A00.000&Update=2013-05-17T00%3A00%3A00.000&__RequestVerificationToken=CfDJ8OfA6sTjcU1PuqxxzGM-oMqFkSNAgkReKvXjTW0EStR_OB4Zz6j90ZdieDNspaE86824rUys1Av2cI9mKtO15RaMnYSiz1_As63Ez0XWxX4N3zfL4vlgGfPQ43FMqqfcPBAG33xvi4G0naOTHEVTdGbiwkLrK2UVF2O01JzfVW3olYbxna45Pg10haFTI-s5QgHTTP/1.1 302 FoundDate: Mon, 01 Jul 2019 16:19:16 GMTServer: KestrelContent-Length: 0Location: /Home/ViewProjects Failure (Edit Comments)POST /Home/EditComment/1 HTTP/1.1Cache-Control: max-age=0Connection: Keep-AliveContent-Type: application/x-www-form-urlencodedAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3Accept-Encoding: gzip, deflate, brAccept-Language: en-US,en;q=0.9,mt;q=0.8Cookie: .AspNetCore.Antiforgery.x5eNnYCJ5UA=CfDJ8OfA6sTjcU1PuqxxzGM-oMrl1aZfFqqMphsPHMioPYeJIj8tRRSXB1N9Pm7JhspsKDyUKawAVJYkSlP56myEU4qcRohQ1axrDWFXPVvZjlNZqiRZAZVOMcZ3wupV12M_z289E7MaUrZ1nbOzH34eiH0; .AspNetCore.Identity.Application=CfDJ8OfA6sTjcU1PuqxxzGM-oMqsILl7uDq3qp0MgEGexCwq_b2cNi4376Wt5jxWgINpwDxVRedde5wkOvqycIGfKrQJM2uCVgFMc75i-3Ch_Sct3wFtj_o2wHjLt9OSgM1dieKWdY8BVsLWGHIsMkceMbh_GQz6xJsKrOixjijHUw88p990DPKm2dGJo-JLSHJpqxGNkQxlhPNPf-VsHEQmh27Mn2ah_NZj0NqIlxDuxfmeLQoV0W1s99zVg7URMUbSmGQsShrT1HxhcUjesLuGnyy90GdxmFyGf2-RKPl1zGdkQhaIgicmxQi-bR8otlu5E1uHPms-_HR3xZwT3koowKFYNM4NFHfPuQOwPgZooHCJeaYvweHuqiB5Oh98c6gRHalMSUqGApIICOfVY7mrr9uxt70PeB60PisyAfASCClKf0IsnJLh8flRZ5lr7cr4fhVXU9Jn-PS_09-iX262WvSgjWiPvfe6W_3QxhnPV1NBb0xVy7FCBNMeIIge0BftQzGMb0h_2xsCITwf9oAApXH-uTnC4E2FZI1nUzdfRVPCrj0kXsppeVr6q-65d9_cWgh2aDC4EYeCF4v__Yz9IZPoMKCvHF_rq_Vna4jLPLsobt4VcViYrSY66JmtO9IeoXpA3Ivd2P7ws4lcnJ9STgFV4oP3hmC4aRdA1BURRzz2Host: localhost:44390Referer: https://localhost:44390/Home/EditComment/1User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36origin: https://localhost:44390upgrade-insecure-requests: 1MS-ASPNETCORE-TOKEN: 2a6aebc6-e154-4f02-9517-cae788a1069fX-Forwarded-For: [::1]:61219X-Forwarded-Proto: httpsContent-Length: 606Mp_Post_Id=1&Mp_Guest_Id=1&Comment=lorem+quisque+ut+erat+curabitur+gravida+nisi+at+nibh+in+hac+habitasse+platea+dictumst+aliquam&Karma=1&Approved=1&Ip=21.99.31.96&Agent=Mozilla%2F5.0+%28Macintosh%3B+U%3B+Intel+Mac+OS+X+10_7%3B+en-us%29+AppleWebKit%2F533.4+%28KHTML%2C+like+Gecko%29+Version%2F4.1+Safari%2F533.4&Create=2018-07-17T00%3A00%3A00.000&Update=2012-06-01T00%3A00%3A00.000&__RequestVerificationToken=CfDJ8OfA6sTjcU1PuqxxzGM-oMr9nzkkEn5p6n7jwRflZ1bmxhEOVzWiW7VXO1rmDYbHQR4CvYlmqH4LyuHMPDsQZWXE-gZ3eDU2LWqJd1uVnMKeJcbV0gne1gxSQdeg2Cd7wklVGIJAlC4PNr5hbqJmAGItiemNRukLVKMLVZ0E65dR-pVhxKy4SteMmvnDVMg5_QHTTP/1.1 500 Internal Server ErrorDate: Mon, 01 Jul 2019 17:06:52 GMTContent-Type: text/html; charset=utf-8Server: KestrelTransfer-Encoding: chunkedAdditional InformationProject Configuration myProject.csproj <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.2" /> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.9" /> <PackageReference Include="MySql.data" Version="8.0.16" /> <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.16" /> </ItemGroup> <ItemGroup> <Folder Include="Migrations\" /> </ItemGroup> </Project>Database [mpComment.sql] CREATE TABLE [mpComment] ( [id] INT NOT NULL PRIMARY KEY, [mp_post_id] INT NOT NULL FOREIGN KEY REFERENCES mpPost(id), [mp_guest_id] INT NOT NULL FOREIGN KEY REFERENCES mpGuest(id), [comment] NVARCHAR(500) NOT NULL, [karma] INT NULL, [approved] INT NOT NULL, [ip] NVARCHAR(100) NULL, [agent] NVARCHAR(255) NULL, [create] DATETIME NULL, [update] DATETIME NULL, )Insertion Query CommentsInsertQuery.sql This would be exactly the same data that would be (typically) submitted through the aforementioned form; which works fine. INSERT INTO [profileDb].[dbo].[mpComment] ([mp_post_id], [mp_guest_id], [comment], [karma], [approved], [ip], [agent], [create], [update]) VALUES (1, 1, 'lorem quisque ut erat curabitur gravida nisi at nibh in hac habitasse platea dictumst aliquam', 1, 1, '21.99.31.96', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_7; en-us) AppleWebKit/533.4 (KHTML, like Gecko) Version/4.1 Safari/533.4', '07/17/2018', '06/01/2012');Final ThoughtsI am concerned that this issue might be occurring somewhere within the Entity Framework, where I cannot troubleshoot. If I had a sincere point of origin where I can identify exact point where the data from my browser is captured by the .Net framework, I might be able to better identify the key issue.Similar Post: ASP.NET CORE Web API: Model value is null when doing HTTP Post requests with null Guid This question is very similar to an alternate question, however, there appears to be less troubleshooting, and a lot less information concerning the matter. In addition, there was not much love on this question, and no solutions provided.Thanks in advance, and cheers 解决方案 Jerry Rigged SolutionI was able to manage a workaround, albeit, I'm still not certain "why" this error is occurring.SynopsisSense the post-back data was being captured within the application (Graphic), however, it was not populating the parameter value of the EditComments method, I simply populated the data manually.SolutionIncluded the Microsoft.AspNetCore.Http library within my Home Controller, and modified the following post-back method from: HomeController.cs [HttpPost] public async Task<IActionResult> EditComment(MpComment comment) { comment.Id = 0; _repo.AddComment(comment); if (await _repo.SaveChangesAsync()) return RedirectToAction("ViewComments"); else return View(comment); }to HomeController.cs [HttpPost] public async Task<IActionResult> EditComment() { var form = Request.Form.ToList(); var comment = new MpComment { Id = 0, Mp_Post_Id = Int32.Parse(form.Where(x => x.Key == "Mp_Post_Id").FirstOrDefault().Value), Mp_Guest_Id = Int32.Parse(form.Where(x => x.Key == "Mp_Guest_Id").FirstOrDefault().Value), Comment = form.Where(x => x.Key == "Comment").FirstOrDefault().Value, Karma = Int32.Parse(form.Where(x => x.Key == "Karma").FirstOrDefault().Value), Approved = Int32.Parse(form.Where(x => x.Key == "Approved").FirstOrDefault().Value), Ip = form.Where(x => x.Key == "Ip").FirstOrDefault().Value, Agent = form.Where(x => x.Key == "Agent").FirstOrDefault().Value, Create = Convert.ToDateTime(form.Where(x => x.Key == "Create").FirstOrDefault().Value), Update = Convert.ToDateTime(form.Where(x => x.Key == "Update").FirstOrDefault().Value) }; _repo.AddComment(comment); if (await _repo.SaveChangesAsync()) return RedirectToAction("ViewComments"); else return View(comment); }...and everything works as expected.Additional noteThese values were easy enough to retrieve, in case anyone else has a similar issue. Simply convert the request form data into a List (as above) and print out those results via the output console.Example: [HttpPost] public methodExpectingPostback() { var form = Request.Form.ToList(); foreach (var item in form) { Debug.WriteLine($"{item.Key} : {item.Value}"); } } 这篇关于ASP.NET MVC核心Web POST请求使用NULL值填充数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-30 10:46