. Net provides three string processing functions for us. I believe you have used them all over: trim, trimstart, and trimend.
However, in practical applications, trim one by one is quite troublesome. For analysis, see the following controller and its model:
Public class personcontroller: controller
{
Public actionresult query (string name)
{
//...
}
//...
[Httppost]
Public actionresult create (person)
{
//...
}
[Httppost]
Public actionresult create2 (formcollection collection)
{
Person = new person ();
Updatemodel (person, collection );
//...
}
//...
}
Public class person
{
Public int id {get; set ;}
Public string name {get; set ;}
} There are roughly three trim types:
The string parameter in the action, such as the name parameter in the query method.
The string attribute of complex type parameters in action, such as the name attribute of person in the create method.
Explicitly bound string attributes of complex types in action, such as the name attribute of person in the create2 method.
If the model is more complex:
Public class person
{
Public int id {get; set ;}
Public string name {get; set ;}
Public string [] hobbies {get; set ;}
Public person father {get; set ;}
}