2016-04-02 9 views
1

一部のデータを一部のブートストラップのテキストボックスに表示しようとしています。データベースからデータを取り出し、ビューモデルでビューに渡す

通常、Webフォームでは、データセットを設定し、テキストボックスの.TextプロパティをTextBox.Text=Datatable.Rows[0]["FieldName"].ToString()のようなものを使用して設定しますが、MVCの新機能は私にはわかりません。とにかくここ

は私が私が私がDBからデータを取得し、このようなのActionResultを、持っている

を持っているものです。データはうまくいきます。私がする必要があるのは、一緒に夢中になることだけです。

public ActionResult CompanySettings() 
     { 
      ClaimsIdentity identity = (ClaimsIdentity)User.Identity; 
      int CompanyId = Convert.ToInt32(identity.FindFirst("CompanyId").Value); 
      //----------------------------- 
      ViewBag.CompanyId = CompanyId; 
      ViewBag.Page = "Inbox"; 
      string Name = identity.Name; 
      string CompanyName = identity.FindFirst("CompanyName").Value; 



      ViewBag.Name = Name; 
      ViewBag.CompanyName = CompanyName; 
      //----------------------------- 

      DataSet ds = CompanyDB.Company_Get_Info(CompanyId); 
      return View(); 
     } 

public class CompanySettingViewModel 
    { 
     [Display(Name = "CompanyType")] 
     public CompanyType CompanyType { get; set; } 

     //and many more fields like this. 
    } 

私はどのような場合には、あまりにも私のhtmlの一部を掲載しています(例として、一方のフィールドのみを示す)私のViewModelは

<table> 
    <tr> 
    <td> 
     <div class="registerbox-textbox"> 
      <h6>Company Type</h6> 
     @Html.Bootstrap().TextBoxFor(t=>t.CompanyType).Placeholder("FirmaTipi") 
     </div> 
    </td> 
//again many repeating same type fields inside a table 
<tr> 
<table> 

これはおそらく、非常に単純なものです簡単ですが、私は立ち往生しています。誰にも分かりますか?

答えて

4
public ActionResult CompanySettings() 
    { 
     ClaimsIdentity identity = (ClaimsIdentity)User.Identity; 
     int CompanyId = Convert.ToInt32(identity.FindFirst("CompanyId").Value); 
     //----------------------------- 
     ViewBag.CompanyId = CompanyId; 
     ViewBag.Page = "Inbox"; 
     string Name = identity.Name; 
     string CompanyName = identity.FindFirst("CompanyName").Value; 



     ViewBag.Name = Name; 
     ViewBag.CompanyName = CompanyName; 
     //----------------------------- 

     DataSet ds = CompanyDB.Company_Get_Info(CompanyId); 
     CompanySettingViewModel NewModel= new CompanySettingViewModel(); 
     NewModel.CompanyType = "AnyValue" //Pass the Company Type value to model 
     return View(NewModel); 
    } 

とビューは次のようになります

<table> 
    <tr> 
    <td> 
     <div class="registerbox-textbox"> 
      <h6>Company Type</h6> 
     @Html.TextBoxFor(t=>t.CompanyType, new { @placeholder = "FirmaTipi" }) 
     </div> 
    </td> 
//again many repeating same type fields inside a table 
<tr> 
<table> 
関連する問題