我想从POST数据中去除非数字元素,然后使用UpdateModel
来更新数据库中的副本。有没有办法做到这一点?在ASP.NET MVC UpdateModel发生之前,我可以对POST数据执行一些处理吗?
// TODO: it appears I don't even use the parameter given at all, and all the magic
// happens via UpdateModel and the "controller's current value provider"?
[HttpPost]
public ActionResult Index([Bind(Include="X1, X2")] Team model) // TODO: stupid magic strings
{
if (this.ModelState.IsValid)
{
TeamContainer context = new TeamContainer();
Team thisTeam = context.Teams.Single(t => t.TeamId == this.CurrentTeamId);
// TODO HERE: apply StripWhitespace() to the data before using UpdateModel.
// The data is currently somewhere in the "current value provider"?
this.UpdateModel(thisTeam);
context.SaveChanges();
this.RedirectToAction(c => c.Index());
}
else
{
this.ModelState.AddModelError("", "Please enter two valid Xs.");
}
// If we got this far, something failed; redisplay the form.
return this.View(model);
}
对不起,为了这个简单的工作,希望我的问题很明显吗?也很抱歉,因为这是一个新手问题,我可能能够用几个小时的文档 - 拖网捕获,但是我有时间压力...呃。