HTML Tags for Razor Engine (Asp.net mvc C#)

Asked

Viewed 787 times

1

I’m having difficulty in my web application with Asp.net mvc, of how to create forms using the Razor Engine.

Below follows my HTML code.

<form class="o-form" method="post">
   <input name="senderName" id="senderName" required="required" type="text" placeholder="Nome*">
   <input type="email" name="senderEmail" id="senderEmail" required="required" placeholder="Email*">
   <input type="text" placeholder="website">
   <textarea name="message" id="message"></textarea>
   <button type="submit" class="btn-small btn-center">Send</button>
</form>

To use the Razor Engine, I tried the following:

 @using (Html.BeginForm())
 {
     @Html.ValidationSummary(true)
     @Html.EditorFor(model => model.Nome)
     @Html.ValidationMessageFor(model => model.Nome)
     @Html.EditorFor(model => model.Email)
     @Html.ValidationMessageFor(model => model.Email)
     @Html.TextAreaFor(model => model.Mensagem)
     @Html.ValidationMessageFor(model => model.Mensagem)
     <button type="submit" class="btn-small btn-center">Send</button>
 }

And in that I am facing difficulties with tags: class, placeholer, required, and various tags HTML5, as data-alguma-coisa.

What is the correct way to include these tags in my inputs, using Razor?

1 answer

2


In order for the name and id to be overwritten you must use Textboxfor instead. Look at the example below (I included the class attribute as well):

@Html.Textboxfor(model => model. Name, new { @class = "class", Name = "senderName", Id="senderName", Placeholder="" })

do the same with other fields. As for the form already goes as method post even. do not need to do anything. Just create another action with the same name as the one that displays the form only with the [Httppost] attribute and a model as a parameter to receive the form. Any questions comment there that I try to answer. I hope I’ve helped.

  • Thanks, I was picking up nice and now it all worked out. Thanks for the help.

Browser other questions tagged

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