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個對象以允許你編輯它 - 但它會丟失值。 幫助!