CSS работает нормально для HTML, но не для синтаксиса Razor - PullRequest
0 голосов
/ 15 сентября 2018

Я делаю контактную форму, сначала это был чистый HTML:

<div id="contact-container">
<form class="cf">
    <div class="half left cf">
        <input type="text" id="input-name" placeholder="Name">
        <input type="email" id="input-email" placeholder="Email address">
        <input type="tel" id="input-phone" placeholder="Phone">
        <input type="text" id="input-subject" placeholder="Subject">
    </div>
    <div class="half right cf">
        <textarea name="message" type="text" id="input-message" placeholder="Message"></textarea>
    </div>
    <input type="submit" value="Submit" id="input-submit">
</form>
</div>

Однако, когда я преобразовал его в синтаксис Razor:

<div id="contact-container">
@Html.BeginForm("Contact", "Service", FormMethod.Post, new { @class = "cf" })
{
    <div class="half left cf">
        @Html.TextBoxFor(m => m.Name, new { htmlattributes = new { id = "input-name", placeholder = "Name" }})
        @Html.TextBoxFor(m => m.Email, new { htmlattributes = new { id = "input-email", placeholder = "Email Address" }})
        @Html.TextBoxFor(m => m.Phone, new { htmlattributes = new { id = "input-phone", placeholder = "Phone" }})
        @Html.TextBoxFor(m => m.Subject, new { htmlattributes = new { id = "input-subject", placeholder = "Subject" }})
    </div>
    <div class="half right cf">
        @Html.TextBoxFor(m => m.Message, new { htmlattributes = new { id = "input-message", placeholder = "Message" }})
    </div>
    <input type="submit" value="Submit" id="input-submit">
}
</div>

Выглядит совершенно по-другому, со случайным текстом, таким как System.Web.Mvc.Html.MvcForm { и кучей точек с запятой на веб-странице. Что мне здесь не хватает?

1 Ответ

0 голосов
/ 15 сентября 2018

Вам нужно добавить using вокруг создания формы, например:

<div id="contact-container">
@using (Html.BeginForm("Contact", "Service", FormMethod.Post, new { @class = "cf" })
{
    <div class="half left cf">
        @Html.TextBoxFor(m => m.Name, new { htmlattributes = new { id = "input-name", placeholder = "Name" }})
        @Html.TextBoxFor(m => m.Email, new { htmlattributes = new { id = "input-email", placeholder = "Email Address" }})
        @Html.TextBoxFor(m => m.Phone, new { htmlattributes = new { id = "input-phone", placeholder = "Phone" }})
        @Html.TextBoxFor(m => m.Subject, new { htmlattributes = new { id = "input-subject", placeholder = "Subject" }})
    </div>
    <div class="half right cf">
        @Html.TextBoxFor(m => m.Message, new { htmlattributes = new { id = "input-message", placeholder = "Message" }})
    </div>
    <input type="submit" value="Submit" id="input-submit">
}
</div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...