2016-03-28 82 views
-1

我有以下FinanceProductFeatures表格,我想要顯示每個表格記錄作爲表格的標籤名稱。顯示每個表格數據行作爲標籤

enter image description here

所以我創建的模型類這樣

public class ProductFinanceFeatures 
{ 
    public IList<AB_FinanceProductFeatures> ListProductFinanceFields { get; set; } 
} 
public partial class AB_FinanceProductFeatures 
{ 
    public string ProductFinanceNameEn { get; set; } 
    public string ProductFinance_Value_EN { get; set; }   
} 

那麼這樣

[HttpGet] 
    public ViewResult Financing_Product_Feature_Configuration() 
    { 
     var model = new ProductFinanceFeatures 
     { 
      ListProductFinanceFields = db.FinanceProductFeatures.ToList() 
     }; 

     return View(model); 
    } 

控制器類,那麼它的ViewPage這樣

@model albaraka.Models.ProductFinanceFeatures 

@{ 

} 

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

    <div class="form-horizontal"> 

     @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 

     @for (int i = 0; i < Model.ListProductFinanceFields.Count; i++) 
     { 
      <div class="form-group"> 
       @Html.LabelFor(model => model.ListProductFinanceFields[i].ProductFinanceNameEn, htmlAttributes: new { @class = "control-label col-md-2" }) 
       <div class="col-md-10"> 
        @Html.TextAreaFor(m => m.ListProductFinanceFields[i].ProductFinance_Value_EN, new { @row = 5 }) 
       </div> 
      </div> 
     } 

     <div class="form-group"> 
      <div class="col-md-offset-2 col-md-10"> 
       <input type="submit" value="Save" class="btn btn-default" /> 
      </div> 
     </div> 
    </div> 
} 

但在這裏我沒有得到預期的結果,無法呈現標籤

出這樣

enter image description here

+0

您可能想要使用此重載:https://msdn.microsoft.com/en-us/library/system.web.mvc.html.labelextensions.labelfor(v=vs.118).aspx#Anchor_7 – Hendry

+0

你期望看到什麼? –

+0

您是否嘗試了HTML.Displayfor? 使用HTML.Displayfor而不是HTML.LabelFor –

回答

-1

只需簡單地用DisplayFor爲如下─

<div class="col-md-10"> 
     @Html.DisplayFor(m => m.ListProductFinanceFields[i].ProductFinance_Value_EN, new { @row = 5 }) 
</div> 

或者

更換 TextAreaFor
<div class="col-md-10"> 
    @Html.DisplayTextFor(m => m.ListProductFinanceFields[i].ProductFinance_Value_EN) 
</div> 

希望這對你有用..!

+0

* *應該如何改變相同的顯示值「ProductFinanceName」? –

相關問題