gpt4 book ai didi

twitter-bootstrap - MVC Bootstrap 表单样式问题

转载 作者:行者123 更新时间:2023-12-04 22:30:49 24 4
gpt4 key购买 nike

我的 bootstrap mvc 表单有一个小问题。当我添加 Razor 时,表单组的边距似乎不起作用。任何帮助将不胜感激。

enter image description here

这是没有正确采用样式的形式

 @using (Html.BeginForm("Contact", "Home"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="formGroupInputLarge1" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control", placeholder = "Fullname", tabindex = 1 })
@Html.ValidationMessageFor(m => m.Name)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge2" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder = "Email Address", tabindex = 2 })
@Html.ValidationMessageFor(m => m.Email)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge3" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
@Html.TextAreaFor(m => m.Message, new { @class = "form-control", placeholder = "Message", tabindex = 3 })
@Html.ValidationMessageFor(m => m.Message)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary btn-lg">Send Mail</button>
</div>
</div>
</form>
}

但是一旦我删除了 Begin 表单,它就会采用正确的样式
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="formGroupInputLarge1" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control", placeholder = "Fullname", tabindex = 1 })
@Html.ValidationMessageFor(m => m.Name)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge2" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder = "Email Address", tabindex = 2 })
@Html.ValidationMessageFor(m => m.Email)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge3" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
@Html.TextAreaFor(m => m.Message, new { @class = "form-control", placeholder = "Message", tabindex = 3 })
@Html.ValidationMessageFor(m => m.Message)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary btn-lg">Send Mail</button>
</div>
</div>
</form>

最佳答案

您创建的嵌套表单(表单中的表单)无效且不受支持。改变

@using (Html.BeginForm("Contact", "Home"))


@using (Html.BeginForm("Contact", "Home", FormMethod.Post, new { @class="form-horizontal", role="form" }))

并删除第二个表单元素(及其结束标记)
<form class="form-horizontal" role="form">

作为旁注, <label for="formGroupInputLarge1" ...>未创建正确的 labelfor 开始的元素属性与表单中的任何元素都没有关系。而是使用 @Html.LabelFor(m => m.Name, new { @class = "col-sm-2 control-label" })它将标签与文本框相关联。

关于twitter-bootstrap - MVC Bootstrap 表单样式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26952457/

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