2011-07-15 49 views
0

我正在寻找部分编辑我的模型 - 场景是我想要显示5个字段,并且2个字段应该是可编辑的,并且在发布帖子时它应该更新可编辑的字段,强类型视图提供完全可编辑的视图或详细视图,我怎么可以结合使用。任何意见或帮助将不胜感激。如何在mvc中显示单个视图的编辑和详细信息

<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

我们可以有一些代码示例请求SE? – simonlchilds

+0

编辑......... –

+0

哦,凯...那么你需要更新什么,你的'<%使用(Html.BeginForm()){}'块和你如何使用MVC2项目中的MVC3 ViewBag属性? – simonlchilds

回答

2

你实现所有的错在这里。首先,不要用<table>的处处进行布局,可以使用MVC模板,只需将div标签浮动即可。

您需要一个ViewModel其中您可以引用您的Booking对象,我认为它是一个数据库对象?

喜欢的东西...

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); 
} 
相关问题