В мой контроллер, я всегда в конечном итоге что-то вроде:Как передать функцию методу?
[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' Action <>' ' Func <> ' –