【发布时间】:2010-11-26 15:41:59
【问题描述】:
您好,我有以下视图,它从包含 ApplicationSettingEntity 类实例的视图数据中获取表单字段的值。 ApplicationSettingEntity 类包含一个机器实体类的实例作为属性之一。表单由来自的值填充 项目.Id item.Key item.Machine.Name
当我编辑值时,表单返回 item.Id 和 item.Key 的更新值,但不返回 item.Machine.Name
我在为表单补水时检查了 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>
【问题讨论】:
标签: c# asp.net-mvc