html - CSS 适用于 HTML 但不适用于 Razor 语法
问题描述
我正在制作联系表格,起初它是纯 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>
推荐阅读
- git - 与其他人共享的远程机器内基于令牌的 github 访问
- qemu - QEMU 在 M1 Mac Mini 上构建失败,状态为:qemu-system-x86_64: qemu_mprotect__osdep: mprotect failed: Permission denied
- asp.net-mvc-5 - 添加许多图像后,Visual Studio 2019 崩溃
- vim - 在vim中搜索和替换忽略子字符串匹配的精确模式
- python - 具有不同xpath页面对象模型pytest python的相似页面的相同方法
- c - 具有相同键和 msgqid 的消息队列的多个条目
- javascript - React-chart.js 2 模块中的错误,但已安装在 package.json 文件中
- c# - 如何确定使用 C# 从服务器发送的两个可用电子邮件中的哪个 IP 地址
- python - train_test_split 错误:“没有足够的值来解包(预期 4,得到 2)”
- c++ - 如何用另一个特征向量填充一个特征向量?