How to put Bootstrap ValidationMessageFor in correct position?

落花浮王杯 提交于 2019-12-03 16:26:35

Please check this JS Fiddle Link

HTML Code:

<!DOCTYPE html>
<body>
    <div class="container">
        <form class="form-signin form-horizontal" role="form">
             <h4 class="form-signin-heading">Please sign in</h4>

            <div class="form-group">
                <div class="col-xs-7 col-sm-7">
                    <input type="username" class="form-control username" placeholder="Username" required="autofocus" />
                </div>
                <div class="col-xs-7 col-sm-5"> <span class="help-inline pull-left">Please correct the error</span>

                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-7 col-sm-7">
                    <input type="password" class="form-control password" placeholder="Password" />
                </div>
                <div class="col-xs-7 col-sm-5"> <span class="help-inline pull-left">Please correct the error</span>

                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-7 col-sm-7">
                    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
                </div>
            </div>
        </form>
    </div>
    <!-- /container -->
    <!-- Bootstrap core JavaScript==================================================- ->
    <!-- Placed at the end of the document so the pages load faster -->
</body>

I hope this is what you want to achieve.

If you have any other issue or if not solved, then please add a comment below.

Regards D.

Have you tried this? (untested)

  <div class="controls">
    <input type="text" id="inputError" class="pull-left">
    <span class="help-inline pull-left">Please correct the error</span>
  </div>

ps.would be great if you make a fiddle.

Elnaz

Use style = "display:inline" for EditorFor and ValidationMessageFor both, as below:

<div class="form-group">
    @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2"})

    <div class="col-md-9">
        @Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @class = "form-control", style = "display:inline" } })
        @Html.ValidationMessageFor(model => model.UserName, "*", new { @class = "text-danger", style = "display:inline" })
    </div>

</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!