gpt4 book ai didi

html - CSS 适用于 HTML 但不适用于 Razor 语法

转载 作者:太空宇宙 更新时间:2023-11-04 01:05:21 25 4
gpt4 key购买 nike

我正在制作一个联系表格,起初它是纯 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 {这样的随机文本和一堆分号。我在这里缺少什么?

最佳答案

您需要在表单创建周围添加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>

关于html - CSS 适用于 HTML 但不适用于 Razor 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52340379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com