在我的控制器中,我总是得到类似的结果:
[HttpPost]
public ActionResult General(GeneralSettingsInfo model)
{
try
{
if (ModelState.IsValid)
{
// Upload database
db.UpdateSettingsGeneral(model, currentUser.UserId);
this.GlobalErrorMessage.Type = ErrorMessageToViewType.success;
}
else
{
this.GlobalErrorMessage.Type = ErrorMessageToViewType.alert;
this.GlobalErrorMessage.Message = "Invalid data, please try again.";
}
}
catch (Exception ex)
{
if (ex.InnerException != null)
while (ex.InnerException != null)
ex = ex.InnerException;
this.GlobalErrorMessage.Type = ErrorMessageToViewType.error;
this.GlobalErrorMessage.Message = this.ParseExceptionMessage(ex.Message);
}
this.GlobalErrorMessage.ShowInView = true;
TempData["Post-data"] = this.GlobalErrorMessage;
return RedirectToAction("General");
}
我想做的是:
[HttpPost]
public ActionResult General(GeneralSettingsInfo model)
{
saveModelIntoDatabase(
ModelState,
db.UpdateSettingsGeneral(model, currentUser.UserId)
);
return RedirectToAction("General");
}
我如何将函数作为参数传递?就像我们在 javascript 中做的那样:
saveModelIntoDatabase(ModelState, function() {
db.UpdateSettingsGeneral(model, currentUser.UserId)
});