LoginSignup
2
0

More than 3 years have passed since last update.

【ASP.Net Core】@Html.TextAreaForでrowsとcolsが効かなかった状況への対処

Last updated at Posted at 2019-06-17

問題

以下のようにTextAreaForを作成した所、css側の設定が優先されてしまい、rowsやcolsが効かない状況になりました。
普通にHTMLとして入力した場合はこの問題は発生しませんでした。

cshtml
@Html.TextAreaFor(
    model => model.Model.Description,
    6,  // rows
    86, // cols
    new { @class = "form-control"}
)
出力されたページ
<textarea class="form-control" cols="86" id="Model_Description" name="Model.Description" rows="6"></textarea>

対処

stylewidth: auto !important; height: auto !important;を指定すればできました。

cshtml
@Html.TextAreaFor(
    model => model.Model.Description,
    6,  // rows
    86, // cols
    new { @class = "form-control", @style = "width: auto !important; height: auto !important;" }
)
出力されたページ(整形済み)
<textarea
  class="form-control" cols="86" id="Model_Description" name="Model.Description"
  rows="6" style="width: auto !important; height: auto !important;"
></textarea>

感想

一応rowsとcolsを使えるようにしましたが強引なやり方になっているので、この場合無理にrowsとcolsを使ってサイズを設定するよりcssで設定した方がいいんじゃないかと思います。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0