在我的控制,我總是最後的東西,如:如何將函數傳遞給方法?
[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)
});
'行動 myFunction' –
''delegate'行動<>'' Func <>' –