TextBoxFor with whitespace

2

I have a TextBoxFor that lists the record of a table field. When displaying in the view, the textbox throws whitespace after displaying the contents of the record. I noticed that these spaces are to complete the StringLegth defined in the model for maximum size of characters allowed for the textBoxFor

[Required(ErrorMessage = "Campo obrigatório")]
[Display(Name = "Responsável")]
[StringLength(80, ErrorMessage = "Informe no máximo 80 caracteres")]
public string Responsavel { get; set; }

In View I put TextBoxFor

@f.FormGroup().TextBoxFor(p => p.Responsavel).WidthMd(6).Placeholder("Professor responsável pelo projeto.")

And the field is listed as follows:

"Joao da Silva 'several blank spaces'" (without the quotation marks, I put the quotation marks to show that a blank is being applied).

I have other forms that I did the same way and this does not happen, why the hell is this white space included? Before anyone asks, the record in the DB has no spaces.

    
asked by anonymous 18.10.2017 / 13:19

2 answers

1

I discovered the problem :

The field in Sql Server was as nchar , with the correct field being nvarchar . Who was populating the values with spaces was the bank.

    
20.10.2017 / 15:57
0

I believe the error is here:

[StringLength(80, ErrorMessage = "Informe no máximo 80 caracteres")]

You are setting the length of the string, forcing the system to complete the missing amount, try setting a maxlength on the object and not on the string.

    
19.10.2017 / 19:41