Textboxfor with white spaces

Asked

Viewed 111 times

2

I have a Textboxfor that lists the record of a table field. When displaying in the view, the textbox throws blank spaces after displaying the record content. I realized that these spaces are to complete the Stringlegth set in the model for maximum allowed character size 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 the Textboxfor

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

And the field is listed as follows:

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

I got other forms I made the same way and it doesn’t happen, why the hell is this blank space included? Before anyone asks, the comic book record has no spaces.

  • Apparently vc is using some extensions in the helper Html. Not knowing what they do makes it hard to help. You can post their content?

  • In BD the field is Char or Varchar?

2 answers

1

I found the problem:

The field in Sql Server was as nchar, when the right thing is nvarchar. Who was populating values with spaces was the bank.

  • Do not use the question field for comments.

0

I believe the error is here:

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

you are setting the size of the string, forcing the system to complete the missing amount, try to define a maxlength in the object and not in the string.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.