如何将@html.editorfor 居中?

Posted

技术标签:

【中文标题】如何将@html.editorfor 居中?【英文标题】:How to put @html.editorfor to center? 【发布时间】:2020-11-01 04:36:56 【问题描述】:

我要制作一个更新自行车的编辑页面。我一直在使用引导程序进行 html 设计,但看起来它不再正常工作了。这是我的代码;

 @model Avent.Entity.Bike

@
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";


<h2>Edit Bike @Model.Brand @Model.BikeModel</h2>

@using (Html.BeginForm())

    @Html.AntiForgeryToken()
    
<div class="form-horizontal col-12 text-center">
    <h4>Bike</h4>
    <hr />
    @Html.ValidationSummary(true, "", new  @class = "text-danger" )
    @Html.HiddenFor(model => model.Id)
    <img class="img-thumbnail" src="@Model.Image" />
    <div class="form-group text-center">
        @Html.LabelFor(model => model.CreationDate, htmlAttributes: new  @class = "control-label col-md-2" )
        <div class="col-md-6 text-center">
            @Html.EditorFor(model => model.CreationDate, new  htmlAttributes = new  @class = "form-control"  )
            @Html.ValidationMessageFor(model => model.CreationDate, "", new  @class = "text-danger" )
        </div>
    </div>

我尝试了我能做的任何事情,但标签放在中心而文本框没有。 :(你能帮帮我吗?

【问题讨论】:

【参考方案1】:

您可以使用Bootstrap 网格系统中的“.justify-content-center”或“.offset-md-3”类。

这是一个示例代码。 https://www.codeply.com/p/CH1zSO7u6j

【讨论】:

以上是关于如何将@html.editorfor 居中?的主要内容,如果未能解决你的问题,请参考以下文章

Python 操作Redis

python爬虫入门----- 阿里巴巴供应商爬虫

Python词典设置默认值小技巧

《python学习手册(第4版)》pdf

Django settings.py 的media路径设置

Python中的赋值,浅拷贝和深拷贝的区别