2016-12-23 9 views
0

私のテキストボックスのhtmlAttributeが機能しない理由を知ることができますか?私は@ Html.BeginFormを使用していて、他の部分に続く部分のハイパーリンクのみを使用しています。MVC view htmlAttribute not working

以下は私のコードです。

@using (Html.BeginForm()) 
    { 
    @token 

    <div class="form-horizontal"> 
    <h4>StoreDetail</h4> 
    <hr /> 
    @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 
    @Html.HiddenFor(model => model.StoreId) 


    <div class="form-group"> 
     @Html.LabelFor(model => model.NoOfSeat, htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
     @Html.EditorFor(model => model.NoOfSeat, new { htmlAttributes = new { @class = "form-control" } }) 
     @Html.ValidationMessageFor(model => model.NoOfSeat, "", new { @class = "text-danger" }) 
     </div> 
    </div> 

    <div class="form-group"> 
     @Html.Label("Hyperlink", htmlAttributes: new { @class = "control-label col-md-2" }) 
     <div class="col-md-10"> 
     @Html.TextBox("Hyperlink", ViewData["Hyperlink"], new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } }) 
     </div> 
    </div> 

Screenshot of the problem.

私は

new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } }) 

を削除した場合、それが機能していないようにそれは同じビューになります。

+0

'新しい{htmlAttributes =新しい{@class = "フォームコントロール"、@ReadOnly =} "読み取り専用"}新しい{@class = "フォームコントロール"'と 'を置き換える、@ReadOnly = "readonly"} 'とチェックしてください –

+0

試しましたか? –

+1

@RajshekarReddyその作業!ありがとう。 :D – Farid

答えて

4

new { @class = "form-control", @readonly = "readonly" } 

あなただけEditorForヘルパーNew Features in ASP.NET MVC 5.1のためにサポートされて使用している構文を使用してこの構文

new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } } 

を交換してください。

enter image description here

+0

助けてくれてありがとう。それは完全に働いています:D – Farid

+0

それは答えではありません。彼は '' htmlAttributes'属性がなぜ機能していないのかを尋ねています。 mvc 5の有効なシンセックスであるため –