Bhautik Savaliya
Bhautik Savaliya

Reputation: 45

asp-for tag helper showing 'CS1061' error

I am new to the ASP.NET core MVC framework. I am trying to implement server-side validation on the form using tag helper in my MVC application. When I am trying to use asp-for tag helper, it is showing CS1061 error for the string that I am passing as a value of the tag helper.

Below is the code.

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<body>
  <form class="signup" id="form" onsubmit="return validateForm()" asp-action="CreateUser" method="POST">
       <div class="form-div">
           <div class="name-section">
              <input class="textfields field-margin" type="text" placeholder="First Name" id="fname" name="firstname" asp-for="firstname">  // getting error here.
              <input class="textfields" type="text" placeholder="Last Name" id="lname" name="lastname">   
       </div>
   </form>
<body>

I couldn't figure out what is wrong here. Please let me know if additional details are required.
Thanks in advance!

Upvotes: 1

Views: 456

Answers (1)

Serge
Serge

Reputation: 43931

since you are using asp-for , you need to add model to your view in order you could assign the model property.

@model MyViewModel

or if you have the one already , check spelling

Upvotes: 1

Related Questions