我想從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);
}
對不起,爲了這個簡單的工作,希望我的問題很明顯嗎?也很抱歉,因爲這是一個新手問題,我可能能夠用幾個小時的文檔 - 拖網捕獲,但是我有時間壓力...呃。