加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – LabelFor EditorFor在同一条线上?

发布时间:2020-12-16 07:28:15 所属栏目:asp.Net 来源:网络整理
导读:我有这个代码: div class="editor-label" @Html.LabelFor(model = model.Ticket)/divdiv class="editor-field" @Html.EditorFor(model = model.Ticket) @Html.ValidationMessageFor(model = model.Ticket)/div 如何在同一行上获取标签和复选框(在本例中为复
我有这个代码:

<div class="editor-label">
    @Html.LabelFor(model => model.Ticket)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Ticket)
    @Html.ValidationMessageFor(model => model.Ticket)
</div>

如何在同一行上获取标签和复选框(在本例中为复选框)?我试过删除div,他们仍然出现在不同的行.

谢谢.

解决方法

只需删除分隔它们的div,这对我有用,我得到Ticket [].

另外,如果您知道它是CheckBox,请使用CheckBoxFor

<div>
    @Html.LabelFor(model => model.Ticket)
    @Html.CheckBoxFor(model => model.Ticket)
    @Html.ValidationMessageFor(model => model.Ticket)
</div>

我也使用了这个代码作为OP声明这是他的代码

<div class="editor-field">
    @Html.Label("SMS Alerts?")
    @Html.EditorFor(model => model.GetAll)
</div>

我得到GetAll []

GetAll是我的ViewModel中的一个bool

也用这个

<div>
    @Html.LabelFor(model => model.GetAll)
    @Html.EditorFor(model => model.GetAll)
</div>

我得到GetAll []

还有这个

<div class="editor-field">
    @Html.LabelFor(model => model.GetAll)
    @Html.EditorFor(model => model.GetAll)
</div>

我得到GetAll []

在每种情况下,我的测试都是标签,复选框是内联的

(编辑:李大同)

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

    推荐文章
      热点阅读