Home > Net >  ASP. NET Core Controller Parameters Optional questions
ASP. NET Core Controller Parameters Optional questions

Time:02-05

Everybody is good, here is the method of UserController update

 public async Task UpdateBasicAsync (UserUpdateBasicInput input) 
{
Var entity=await _userRepository. GetAsync (input. Id);
The entity=_mapper. The Map (input, the entity);
Var result=(await _userRepository. UpdateAsync (entity)) & gt; 0;

Return ResponseOutput. Result (Result);
}


Among them, the following UserUpdateBasicInput

 public class UserUpdateBasicInput: Entity 
{
///& lt; Summary>
///picture
///& lt;/summary>
Public string Avatar {get; set; }

///& lt; Summary>
///nickname
///& lt;/summary>
[Required] (ErrorMessage="please enter a nickname")
Public string NickName {get; set; }

///& lt; Summary>
///note
///& lt;/summary>
Public string Remark {get; set; }

///& lt; Summary>
///version
///& lt;/summary>
Public long Version {get; set; }
}



Because Remark does not limit required, if the user Request Body sends the following contents:
 {
"Id" : 6,
"NickName" : "Fuck",
}


So UpdateBasicAsync received input, Remark is null, but the updated value within the database becomes null Remark...
But I don't want to modify the value of the Remark

How to modify, please? Thank you,

CodePudding user response:

Let the value of the Remark had the appearance of the original unchanged, so that he wouldn't change to the database,
The value of the query for the first time to save his fu back before update
  • Related