Hello. I am learning MVC from a book, and the author uses the <input asp-for="Name"/> or something related to asp -... any action with this tag is ignored. When accepting a form, this page does not react in any way, but when replaced with
<input type="text" id="Name" name="Name" /> - the form is sent and everything works. What is the actual problem?

  • I am studying the same MVC, but I have not seen such an asp-for property for the input tag before. Most likely the author used the creation of his attribute. Look in the direction of @ Html.Helper - Pavel Kos
  • Good question: what's the problem if everything works ... - Qwertiy

1 answer 1

asp-for="Name" and other asp-attributes in ASP.NET MVC are not and never have been. Check out your book - most likely it tells you about ASP.NET Core or ASP.NET vNext (old title)

If the book really says that there are such attributes in MVC, throw it away.


The analogue of what you wrote in MVC is to call the helper @Html.TextBoxFor(x => x.Name) or even @Html.EditorFor(x => x.Name) . But for more complex cases, it is sometimes easier to write manually than to look for how else it can be done.

  • Yes, and looked really like that. It turns out, in this case, you need to use the standard input? Or is there some kind of replacement? - bRaze
  • stackoverflow.com/documentation/asp.net-core/2665/… It looks like attribute values ​​can be replaced with form get parameters - HasmikGaryaka
  • Thanks for the answer @ Html.EditorFor (x => x.Name) it helped. - bRaze
  • @HasmikGaryaka you this to what? - Pavel Mayorov