Zidane
Zidane

Reputation: 1904

concatenating strings in razor views

I am trying to concatenate strings firstname and lastname in my model. When I run my project I get an error that reads....*

InvalidOperationException: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

Here is the line of code that is giving me the error.

<input asp-for="@(Model.ContactPersonName + "" + @Model.ContactPersonSurname)" class="form-control" />

Upvotes: 0

Views: 463

Answers (1)

Yiyi You
Yiyi You

Reputation: 18209

If you want to set value with @(Model.ContactPersonName + "" + @Model.ContactPersonSurname),you can use value=....asp-for extracts the name of the specified model property into the rendered HTML. And it can only extract one model property.

<input value="@(Model.ContactPersonName + "" + @Model.ContactPersonSurname)" class="form-control" />

Upvotes: 1

Related Questions