2009-09-08 48 views
0

您好我有以下視圖,從包含類ApplicationSettingEntity的實例的viewdata的表單字段的值。 ApplicationSettingEntity類包含一個機器實體類的實例作爲屬性之一。形式由值填充從 item.Id item.Key item.Machine.Name窗體不會返回所有更新值,而編輯

當我編輯的形式返回item.Id更新的值的價值和item.Key但不item.Machine。名稱

我檢查了item.Machine.Name的值,因爲我正在補充表單,它正確設置文本框的值,但是當我點擊保存按鈕時,爲item.Machine返回的數據爲空。我究竟做錯了什麼?

 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> 

     <%@ Import Namespace="AppSettings.Web.Models" %> 
     <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
      Edit Application Setting 
     </asp:Content> 
     <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 
      <strong style="color: Black;"> 
      <div> 
       <% if (ViewData["ApplicationSetting"] != null) 
        { 
         var item = (ApplicationSettingEntity)ViewData["ApplicationSetting"]; 
       %> 
         <%=Html.ActionLink("Back to List", "Index", 
                 new 
                  { 
                   controller = "ApplicationSettings", 
                   Applications = item.Id, 
                   Machines = item.Machine.Id 
                  })%> 
         </div> 
         <%=Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.")%> 
         <% 
          using (Html.BeginForm((bool)ViewData["IsAdd"] ? "SaveAdd" : "SaveEdit", "ApplicationSettings")) 
          {%>   
           <fieldset> 
            <legend><strong>Application Name:</strong> 
            </legend> 
            <p> 
             <label for="Id" style="font-weight: bold;"> 
              Application Setting Id:</label> 
             <%=Html.TextBox("Id", item.Id)%> 
             <%=Html.ValidationMessage("Id", "*")%> 
            </p> 
            <p> 
             <label for="Key" style="font-weight: bold;"> 
              Application Setting Key:</label> 
             <%=Html.TextBox("Key", item.Key, new {style = "width:400px;"})%> 
             <%=Html.ValidationMessage("Key", "*")%> 
            </p> 
            <p> 
             <span style="font-weight: bold;">Machine Name: </span>    
             <%=Html.TextBox("MachineName", item.Machine.Name)%> 

            </p> 
            <p> 
             <input type="submit" value="Save" /> 
            </p> 
           </fieldset> 
           <% 
          }%> 
         <div> 
          <%=Html.ActionLink("Back to List", "Index", 
                  new 
                   { 
                    controller = "ApplicationSettings", 
                    applicationId = item.Application.Id, 
                    machineId = item.Machine.Id 
                   })%> 
         </div> 
         <% 
       }%> 
     </asp:Content> 

回答

3

你得到這個職位的價值在該項目的形式收集MachineName,因爲這是Html.TextBox

的第一個參數
相關問題