2011-07-15 13 views
0

私は部分的に私のモデルを編集したいと思っています - シナリオは5つのフィールドを表示したい、2つのフィールドは編集可能でなければなりません。完全に編集可能なビューまたは詳細ビューのいずれかを提供します。どのように組み合わせて使用​​できますか。アドバイスや助けをいただければ幸いです。mvcの1つのビューで編集と詳細を表示する方法

<tr><td>Booking ID</td><td><%: Model.ID %></td></tr> 
        <tr><td>Transaction No.</td><td><%: Model.TransactionNumber %>&nbsp;(<%: Model.PaymentProvider %>)</td></tr> 
        <tr><td>Date</td><td><%: String.Format("{0:g}", Model.DateAdded) %></td></tr> 
        <tr><td>Name</td><td><%: ViewBag.account.FirstName %>&nbsp;<%: ViewBag.account.LastName %></td></tr> 
        <tr> 
         <td> 
          <div class="editor-label"> 
           <%: Html.Label("Event") %> 
          </div> 
         </td> 
         <td> 
          <div class="editor-field"> 
           <%: Model.Event.Name %><%: Model.Event.Description %> 
          </div> 
         </td> 
        </tr> 
        <tr><td valign="top">Address</td><td><%= HtmlFormatting.FormatAddress(ViewBag.address)%></td></tr> 
        <tr><td>Cost</td><td>&pound;<%: String.Format("{0:F}", Model.Cost) %></td></tr> 
        <tr><td>Status</td><td><%: ViewBag.status %></td></tr> 

のthnx

+0

いくつかのコード例がありますか?セ? – simonlchilds

+0

編集済み......... –

+0

Oh kay ...更新する必要がありますか?<%%(Html.BeginForm()){} 'ブロックを使用していますか? MVC2プロジェクトのMVC3 'ViewBag'プロパティ? – simonlchilds

答えて

2

あなたの実装はここにすべて間違っています。まず、<table>をレイアウトに使用しないでください。MVCテンプレートを使用して、divタグを残してください。

Bookingオブジェクトを参照できる範囲内にあるViewModelが必要です。これはデータベースオブジェクトと見なされますか?

のような何か...

public class BookingViewModel 
{ 
    public Booking Booking { get; set; } 
} 

そして、あなたはあなたのViewあなたのコントローラからは

public ActionResult Index() 
{ 
    return View(new BookingViewModel()); 
} 

にそれを渡す呼び出すとき次に、あなたのコントローラにPostアクションの結果を追加することができたことができます内プロパティを更新する

[HttpPost] 
public ActionResult Index(BookingViewModel model) 
{ 
    //Update your properties 
    return View(model); 
} 
関連する問題