Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:53:48+00:00 2026-06-06T04:53:48+00:00

In my controller, I always end up with something like: [HttpPost] public ActionResult General(GeneralSettingsInfo

  • 0

In my controller, I always end up with something like:

[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");
}

and what I would like to do would something like:

[HttpPost]
public ActionResult General(GeneralSettingsInfo model)
{
    saveModelIntoDatabase(
        ModelState, 
        db.UpdateSettingsGeneral(model, currentUser.UserId)
    );

    return RedirectToAction("General");
}

How would I pass a function as a parameter? Just like we do in javascript:

saveModelIntoDatabase(ModelState, function() {
    db.UpdateSettingsGeneral(model, currentUser.UserId)
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:53:50+00:00Added an answer on June 6, 2026 at 4:53 am

    It sounds like you want a delegate. It’s not immediately obvious to me what your delegate type should be here – possibly just Action:

    SaveModelIntoDatabase(ModelState, 
        () => db.UpdateSettingsGeneral(model, currentUser.UserId));
    

    Where SaveModelIntoDatabase would be:

    public void SaveModelIntoDatabase(ModelState state, Action action)
    {
        // Do stuff...
    
        // Call the action
        action();
    }
    

    If you want the function to return something, use a Func; if you need extra parameters, just add them as type parameters – there’s Action, Action<T>, Action<T1, T2> etc.

    If you’re new to delegates, I’d strongly suggest getting much more familiar with them before going much further in C# – they’re really handy, and an essential part of modern idiomatic C#. There’s a lot on the web about them, including:

    • MSDN delegates introduction (linking to other articles)
    • My article on delegates and events
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
My Controller: public ActionResult ExportTo(ExportFormat exportFormat = ExportFormat.Xlsx) { ExportType exportType = GridViewHelper.ExportTypes.SingleOrDefault(x =>
I'm trying to make a view controller that will always load the same nib.
With IB storyboards there is always a default view controller selected, which is the
Right now it always goes to default.aspx that subsequently opens the default controller but
controller: def get_nodes ... render :text => nodes.to_json.to_s end which renders valid JSON (
my controller is like this $content = View::factory('user/biochemistryTestForm') ->bind('result', $result); $this->template->content = $content; //here
I'm recoding a splitview controller app I did so the table view isn't always
before_filter :only => :destroy do |controller| controller.is_object_on_same_account_as_current_account_for_id?(controller_name.classify.constantize, params[:id]) end generates error: NameError: undefined local
I would like to test a controller that directly renders some JSON output (by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.