HTML tags for Razor Engine (asp.net mvc C #)

1

I'm having trouble with my web application with asp.net mvc, how to create forms using the Razor Engine.

Below is 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 Razor Engine, I have 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 this I am facing difficulties with the tags: class , placeholer , required , and several HTML5 tags, such as data-alguma-coisa .

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

    
asked by anonymous 03.01.2015 / 15:02

1 answer

2

In order for the name and id to be overwritten, you must use TextBox for EditFor instead. Look at the example below (I include the class attribute too):

@Html.TextBoxFor (model => model.Name, new {@class="class", Name="senderName", Id="senderName", Placeholder="Enter your name"

Do the same with the other fields. As for the form already goes as method post itself. you do not have to do anything. Just create another action with the same name that displays the form only with the attribute [HttpPost] and a model as parameter to receive the form. Any doubts that I'm trying to answer. I hope I have helped.

    
03.01.2015 / 16:00