加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – MVC Bootstrap形成样式问题

发布时间:2020-12-17 20:39:29 所属栏目:安全 来源:网络整理
导读:我的bootstrap mvc表单有一个小问题.当我添加我的剃刀时,表单组的边距似乎不起作用.任何帮助将不胜感激. 这种形式不能正确地进行样式化 @using (Html.BeginForm("Contact","Home")){@Html.AntiForgeryToken()@Html.ValidationSummary(true)form class="form-
我的bootstrap mvc表单有一个小问题.当我添加我的剃刀时,表单组的边距似乎不起作用.任何帮助将不胜感激.

这种形式不能正确地进行样式化

@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,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,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,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”...>没有创建正确的标签元素,因为for属性与表单中的任何元素没有关系.而是使用@ Html.LabelFor(m => m.Name,new {@class =“col-sm-2 control-label”}),它将标签与文本框相关联.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读