飞扬的Blog
主页
登录
TryUpdateModelAsync 的使用记录
"date"
:
"2020-06-01 17:33:49"
"classfiy"
:
"asp.net core"
"author"
:
"飞扬"
"viewTimes"
:
294
返回
###### TryUpdateModelAsync()方法更新部分字段时: ```csharp //函数原型 public Task<bool> TryUpdateModelAsync<TModel>(TModel model, string prefix, params Expression<Func<TModel, object>>[] includeExpressions) where TModel : class; //调用 await TryUpdateModelAsync(oldblog, "", b => b.Title, b => b.ReleaseDate, b => b.Content, b => b.Private, b => b.Classify) ``` >参数解释: 1. 数据库查询出的要修改的对象。 2. 查找当前值时要使用的前缀(我不理解)。 3. 要修改的字段。 这个方法他是利用 [HttpPost] 过来的 Request.Form 中的内容来修改的,Request.Form 中的 IFormCollection 又是只读字段,不能修改内容。但是 Request.Form 是可以修改的,我们可以利用遍历 Request.Form 的 Keys 来创建我们自己的 FormCollection 对象,在遍历的过程中处理想要处理的内容即可。