Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc postback
    text
    copied!<p>I have a controller with the following two Edit methods. The edit form displays correctly with all additional dropdown lists from the FormViewModel. However, when I changed some field values and submitted the form. None of the changed fields were saved. The fields in the postbask collection have default or null values. I have another edit form which update another table. On submit, the changed values are saved. Does anyone know why?</p> <pre><code>// GET: /Transfers/Edit/5 public ActionResult Edit(int id) { Transfer transfer = myRepository.GetTransfer(id); if (transfer == null) return View("NotFound"); return View(new TransferFormViewModel(transfer)); } // // POST: /Transfers/Edit/5 [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, Transfer collection) { Transfer transfer = vetsRepository.GetTransfer(id); if (transfer == null) return View("NotFound"); else { try { UpdateModel(transfer); vetsRepository.Save(); return RedirectToAction("Details", new { id = transfer.TransfersID }); } catch { ModelState.AddModelErrors(transfer.GetRuleViolations()); return View(new TransferFormViewModel(transfer)); } } } </code></pre> <hr> <p>Here is the Edit.aspx and the user control ASCX:</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage&lt;VETS.Controllers.TransferFormViewModel&gt;" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt; Edit &lt;/asp:Content&gt; &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt; &lt;% Html.RenderPartial("TransferForm"); %&gt; &lt;div&gt; &lt;%=Html.ActionLink("Back to List", "Index") %&gt; &lt;/div&gt; &lt;/asp:Content&gt; </code></pre> <p>===================================================================================</p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;VETS.Controllers.TransferFormViewModel&gt;" %&gt; &lt;% var thisTransfer = Model.Transfer; var thisVeteran = thisTransfer.Veteran; %&gt; &lt;%= Html.ValidationSummary("Please correct the errors and try again.") %&gt; &lt;% using (Html.BeginForm()) { %&gt; &lt;fieldset&gt; &lt;legend&gt;&lt;%= (thisTransfer == null) ? string.Empty : (thisTransfer.OffList ? "Off List" : " On List")%&gt;&lt;/legend&gt; &lt;div class="sideBySideDiv"&gt; &lt;p&gt; &lt;label for="LastName"&gt;Last Name:&lt;/label&gt; &lt;%= thisVeteran.LastName %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="FirstName"&gt;First Name:&lt;/label&gt; &lt;%= thisVeteran.FirstName %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="LastFourSSN"&gt;SSN:&lt;/label&gt; &lt;%= thisVeteran.LastFourSSN%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="DOB"&gt;DOB:&lt;/label&gt; &lt;%= String.Format("{0:d}", thisVeteran.DOB)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Hospital"&gt;Hospital:&lt;/label&gt;&lt;br /&gt; &lt;%= Html.DropDownList("Hospital", Model.NonVaHospitals)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="AdmitDX"&gt;Admit DX:&lt;/label&gt; &lt;%= Html.TextBox("AdmitDX", thisTransfer.AdmitDX)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="BedType"&gt;Bed Type:&lt;/label&gt; &lt;%= Html.DropDownList("BedType", Model.BedTypes)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="AdmitDate"&gt;Admit Date:&lt;/label&gt; &lt;%=Html.TextBox("AdmitDate", string.Format("{0:d}", thisTransfer.AdmitDate))%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="_SC"&gt;%SC:&lt;/label&gt; &lt;%= thisVeteran.PercentSC._SC%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="PCP"&gt;PCP:&lt;/label&gt; &lt;%= thisVeteran.PCP %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="ListStatus"&gt;List Status&lt;/label&gt; &lt;%= Html.DropDownList("ListStatus", Model.StatusTypes)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Ward"&gt;Ward:&lt;/label&gt; &lt;%= Html.TextBox("Ward", thisTransfer.Ward)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="WardPhone"&gt;Ward Phone&lt;/label&gt; &lt;%= Html.TextBox("WardPhone", thisTransfer.WardPhone)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="MDName"&gt;Referred MD:&lt;/label&gt; &lt;%= Html.TextBox("MDName",thisTransfer.MDName)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="MDPhone"&gt;MD Phone:&lt;/label&gt; &lt;%= Html.TextBox("MDPhone", thisTransfer.MDPhone)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="MDPager"&gt;MD Pager:&lt;/label&gt; &lt;%= Html.TextBox("MDPager", thisTransfer.MDPager)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="AdmitTime"&gt;Admit Time:&lt;/label&gt; &lt;%= Html.TextBox("AdmitTime", string.Format("{0:t}",thisTransfer.AdmitTime))%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="CallerName"&gt;Caller Name:&lt;/label&gt; &lt;%=Html.TextBox("CallerName", thisTransfer.Caller_Name)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="CallerPhone"&gt;Caller Number:&lt;/label&gt; &lt;%= Html.TextBox("CallerPhone", thisTransfer.CallerNumber)%&gt; &lt;/p&gt; &lt;p&gt;&lt;label for="TransportElig"&gt;Eligibility:&lt;/label&gt; &lt;%= thisVeteran.TransportElig ? "Yes" : "No" %&gt; &lt;/p&gt; &lt;/div&gt; &lt;div class="sideBySideDiv"&gt; &lt;p&gt; &lt;label for="CaseMgr"&gt;Case Mgr:&lt;/label&gt; &lt;%= Html.TextBox("CaseMgr", thisTransfer.CaseMgrName)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="MgrPhone"&gt;Mgr Phone:&lt;/label&gt; &lt;%= Html.TextBox("MgrPhone", thisTransfer.CaseMgrPhone)%&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="CPRSDate"&gt;CPRS Date:&lt;/label&gt; &lt;%= Html.TextBox("CPRSDate", string.Format("{0:d}",thisTransfer.CPRSDate))%&gt; &lt;%= Html.ValidationMessage("CPRSDate", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="CPRSTime"&gt;CPRS Time:&lt;/label&gt; &lt;%= Html.TextBox("CPRSTime", string.Format("{0:t}",thisTransfer.CPRSTime))%&gt; &lt;%= Html.ValidationMessage("CPRSTime", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="TxPriority"&gt;TXFR Priority:&lt;/label&gt; &lt;%= Html.TextBox("TxPriority", thisTransfer.TXFRPriority)%&gt; &lt;%= Html.ValidationMessage("TxPriority", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="AcceptBy"&gt;Accepted By:&lt;/label&gt; &lt;%= Html.TextBox("PreferMD", thisTransfer.AcceptBy)%&gt; &lt;%= Html.ValidationMessage("AcceptBy", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="OffListReason"&gt;Off List Reason:&lt;/label&gt; &lt;%= Html.DropDownList("OffListReason", Model.OffReasonTypes)%&gt; &lt;%= Html.ValidationMessage("OffListReason", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="InfectionType"&gt;Infection Type:&lt;/label&gt; &lt;%= Html.DropDownList("InfectionType", Model.InfectionTypes)%&gt; &lt;%= Html.ValidationMessage("InfectionType", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="COJ"&gt;COJ:&lt;/label&gt; &lt;% if (thisVeteran.VAHospital != null) %&gt; &lt;%= thisVeteran.VAHospital.VAHospital1 %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="FeePay"&gt;Fee Pay:&lt;/label&gt; &lt;%= Html.DropDownList("FeePay", Model.FeePayReasons) %&gt; &lt;%= Html.ValidationMessage("FeePay", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="Insurance"&gt;Insurance:&lt;/label&gt; &lt;%= thisVeteran.Insurance %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="StatusReport"&gt;Status Report:&lt;/label&gt; &lt;%= Html.TextArea("StatusReport", thisTransfer.StatusReport)%&gt; &lt;%= Html.ValidationMessage("StatusReport", "*") %&gt; &lt;/p&gt; &lt;/div&gt; &lt;div class="sideBySideDiv"&gt; &lt;p&gt; &lt;label for="TxSource"&gt;Trnasfer Out Source:&lt;/label&gt;&lt;br /&gt; &lt;input type="radio" name="TxSource" id="radEd" title="ED"/&gt;Ed &lt;input type="radio" name="TxSource" id="radEdPsych" title="EdPsych"/&gt;EdPsych &lt;%= Html.ValidationMessage("TxOutSource", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="InpatientUnit"&gt;Inpatient Unit:&lt;/label&gt; &lt;%=Html.TextBox("InpatientUnit", thisTransfer.InpatientUnit)%&gt; &lt;%= Html.ValidationMessage("InpatientUnit", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="CBOC"&gt;CBOC:&lt;/label&gt; &lt;%= Html.TextBox("CBOC", thisTransfer.CBOC)%&gt; &lt;%= Html.ValidationMessage("CBOC", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="CLC"&gt;CLC (ASIH):&lt;/label&gt; &lt;%= Html.TextBox("CLC_ASIH", thisTransfer.CLC_ASIH)%&gt; &lt;%= Html.ValidationMessage("CLC_ASIH", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="TxReason"&gt;Treansfer Out Reason:&lt;/label&gt;&lt;br /&gt; &lt;input type="radio" id="radEDdivert" name="txReason" title="EDdivert" /&gt;Ed Divertc&lt;br /&gt; &lt;input type="radio" id="radTrauma" name="txReason" title="Trauma" /&gt;Trauma&lt;br /&gt; &lt;input type="radio" id="radOBGYN" name="txReason" title="OBGYN" /&gt;OBGYN&lt;br /&gt; &lt;input type="radio" id="radBedNA" name="txReason" title="Bed Type Not Available" /&gt;Bed Type Not Available&lt;br /&gt; &lt;input type="radio" id="radNoVet" name="txReason" title="Non_Veteran" /&gt;Non Veteran&lt;br /&gt; &lt;input type="radio" id="radNotEligible" name="txReason" title="Not_Eligible" /&gt;Not_Eligible&lt;br /&gt; &lt;input type="radio" id="radOtherServiceNA" name="txReason" title="Other Services Not Available" /&gt;Other Services Not Available&lt;br /&gt; &lt;input type="radio" id="radTxBackHome" name="txReason"title="Transfer Back to Home VA" /&gt;Transfer Back to Home VA&lt;br /&gt; &lt;%= Html.ValidationMessage("TxOutReason", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="OtherServiceNA"&gt;Service Not Available:&lt;/label&gt; &lt;%= Html.TextBox("OtherServiceNA", thisTransfer.OtherServicesNA)%&gt; &lt;%= Html.ValidationMessage("OtherServiceNA", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="BackToHomeVA"&gt;TXFR to Home VA:&lt;/label&gt; &lt;%= Html.TextBox("BackToHomeVA",thisTransfer.BackToHomeVA) %&gt; &lt;%= Html.ValidationMessage("BackToHomeVA", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="TxID"&gt;Transfer Record ID:&lt;/label&gt; &lt;% %&gt; &lt;%= Html.ValidationMessage("TxID", "*") %&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="ListDate"&gt;Added to List Date:&lt;/label&gt; &lt;%= Html.TextBox("ListDate", string.Format("{0:d}", thisTransfer.AddedToListDate))%&gt; &lt;%= Html.ValidationMessage("ListDate", "*") %&gt; &lt;/p&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;p&gt; &lt;input type="submit" value="Save" /&gt; &lt;/p&gt; &lt;% } %&gt;&lt;!-- close using Html.BeginForm()--&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload