在我的ASP MVC 3站点中,当用户从Producer Type
下拉框中选择Sole Proprietor
的值时,字段集中名称为DSS Specific
的所有值都将被取消,视图重新呈现时更长时间显示。ASP MVC视图在无效时不显示更新的数据
当通过代码步进我可以看到,用户点击save
后,模型对象正确地评估Producer Type
,设置适当的字段null
,并且当视图正在呈现我可以看到,在Model
字段对象实际上是null
他们需要的地方。
但是,该视图仍然会显示在打到save
之前的字段中的值,并且尽管将对象传递给它,但仍然会为这些字段值为null
值。我还打了十几次,以确保页面不会简单地缓存在浏览器中。
CONTROLLER
当模型对象首先被传递回到控制器,它通过一个所谓的ReformatFields
[HttpPost]
public ActionResult Edit(Monet.Models.AgentTransmission agenttransmission)
{
//redirect if security is not met.
if (!Security.IsModifier(User)) return RedirectToAction("Message", "Home", new { id = 1 });
//Tax Id security
ViewBag.FullSSN = Security.IsFullSsn(User);
try
{
agenttransmission = AgentTransmissionValidator.ReformatFields(agenttransmission);
方法运行时,这是在ReformatFields
,其判断是否为不将码取消特定字段。然后将模型对象分配回控制器中上面的agenttransmission
对象。
//TODO: blank out DSS specific fields if not a sole proprietor!
if (!agt.ProducerType.Equals("S") || !agt.DRMrole.Equals("Sole Proprietor"))
{
agt.C8CharAgentCAB0State = null;
agt.C8CharAgentCAB0MktDiv = null;
agt.CONCode = null;
agt.BundleCode = null;
agt.LifeRegion = null;
agt.LifeField = null;
agt.AGYMGMT = null;
agt.INDSGC = null;
agt.PENSGC = null;
agt.GRPSGC = null;
agt.LMKSGC = null;
agt.LDT = null;
agt.GCASBNS = null;
agt.GCOMMSN = null;
agt.GPROFBN = null;
agt.INDSplits = null;
agt.DSTSGC = null;
agt.ANNCommCode = null;
agt.LifeEAPercent = null;
agt.VARPercent = null;
agt.OwnerMaster = null;
agt.LifeMaster = null;
agt.CampaignMaster = null;
agt.RelationshipEffDate = null;
agt.RelationshipDistCode = null;
}
return agt;
}
之后被保存,该agenttransmission
模型的对象又被送回视图
db.SaveChanges();
DisplayPrep();
agenttransmission.displayChannel = getDisplayChannel(agenttransmission);
agenttransmission.FormattedReferenceNumber =
ReferenceConversion.UnobAndFormat(agenttransmission.ReferenceNumber, "S");
return View(agenttransmission);
}
VIEW
正如你可以从下面的截图中看到,该Model
对象是传递回该视图的值为null
的CONCode
和BundleCode
。
然而,页面相同的值之前呈现。
它是不是缓存值,你可以在这里看到的HTML实际上是被渲染的这些值的页面的问题
下面是从实际的代码查看这两个字段
<div class="M-editor-label">
@Html.LabelFor(model => model.CONCode)
</div>
<div class="M-editor-field">
@Html.TextBoxFor(model => model.CONCode, new { maxlength = 2 })
@Html.ValidationMessageFor(model => model.CONCode)
</div>
<div class="M-editor-label">
@Html.LabelFor(model => model.BundleCode)
</div>
<div class="M-editor-field">
@Html.TextBoxFor(model => model.BundleCode, new { maxlength = 6 })
</div>
我意识到这是一个涉及的过程,所以如果我失踪任何你认为会有帮助的,请让我知道。谢谢!
太棒了,感谢您的解释! – NealR