0
我有一个PartialView强类型的视图模型查看强类型查看模型不返回模型回控制器上回发
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VATRateManager_MVC.Models.ViewModels.RateControlEditViewModel>" %>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm("Edit", "Rate", FormMethod.Post))
{ %>
<%=Html.ValidationSummary() %>
<%=Html.HiddenFor(Model => Model.ParentID)%>
<%=Html.HiddenFor(Model => Model.ParentTypeID)%>
<%=Html.HiddenFor(Model => Model.ParentTypeDescription)%>
<%=Html.HiddenFor(Model => Model.RateID)%>
<div >
<%=Html.LabelFor(Model => Model.RateValue)%>
<%=Html.DisplayFor(Model => Model.RateValue) %>
</div>
<div>
<%=Html.LabelFor(Model => Model.StartDate)%>
<%=Html.DisplayFor(Model => Model.StartDate, new { @class = "date" })%>
<%-- <%=Html.EditorFor(Model => Model.StartDate, new { @class = "date" })%>--%>
</div>
<div>
<input type="submit" name="button" value="Edit"/>
</div>
继承人的视图模型
public class RateControlEditViewModel
{
/// <summary>The parent ID is the Rate ID for the Current record. </summary>
[HiddenInput(DisplayValue = false)]
public int ParentID { get; set; }
/// <summary>The parent Type ID is the Type ID for the Current record. </summary>
[HiddenInput (DisplayValue= false)]
public int ParentTypeID { get; set; }
[HiddenInput(DisplayValue = false)]
public string ParentTypeDescription { get; set; }
/// <summary>Rate ID for current record, may be null if adding new rate. </summary>
[HiddenInput(DisplayValue = false)]
public int? RateID { get; set; }
/// <summary>Percentage VAT Rate to 2 decimal places. </summary>
[DisplayName("VAT Rate (%)")]
[Required(ErrorMessage ="Please Supply VAT Rate as percentage value")]
[Range(typeof(Decimal), "0","100")]
public decimal RateValue { get; set; }
/// <summary>Start date from which this VAT Rate will be active, the start date will also be
/// the same value for the previous records End Date to ensure there are no gaps in the Rate.</summary>
[DisplayName("VAT Rate Start Date")]
[DataType(DataType.Date)]
[Required(ErrorMessage="Please Supply Start date from which this VAT rate will become active")]
public DateTime? StartDate { get; set; }
}
而且继承人的控制方法。 ..
[ActionName("Edit")]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(string button, RateControlEditViewModel model)
{ // Do Stuff here
}
我的问题是对象“RateControlEditViewModel模型”传递到控件ller已经失去了它的一些价值... 基本上屏幕应该显示一个对象列表,当你点击“编辑”一个新的视图应该打开显示你点击的1个对象以允许你编辑它 - 但它会丢失值。 帮助!