Results 1 to 3 of 3

Thread: [RESOLVED] How can I call an ActionResult from another ActionResult

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2013
    Posts
    12

    Resolved [RESOLVED] How can I call an ActionResult from another ActionResult

    I am creating a website for User registeration,display,login etc. I am currently trying to display the details of the user who have signed in. But within the actionResult of login I don't know how will i call the actionResult of display? I am new to asp.net. I need suggestions

    Code:
     public ActionResult login()
            {
                try
                {
                    return View();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    
            
            [HttpPost]     
            public ActionResult login(DEntities.Users user)
            {
                try
                {
                    services.CheckUser(user);
                    controlsuccess = services.servicesuccess;
                    if (controlsuccess == true)
                    {
    
                        return RedirectToAction("display");             
                        //return View("display");
                    }
                    else
                    { 
                        return HttpNotFound();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
      public ActionResult display()
            {
    
                return View();
            }
            [HttpPost]
            public ActionResult display(int id = 0)
            {
                try
                {
                    DEntities.Users user = services.GetUserbyId(id);
                    return View(user);
    
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    Last edited by gep13; Nov 8th, 2013 at 01:58 AM. Reason: Added code tags

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: How can I call an ActionResult from another ActionResult

    Firstly, please use formatting tags when posting code snippets. You can see for yourself how hard your code is to read. Have a look around at some other threads with code snippets and see how they're posted. Try my CodeBank threads for example.

    As for the question, you can call RedirectToAction or the like instead of View. That will then invoke another action and return its result.

  3. #3
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How can I call an ActionResult from another ActionResult

    Hello,

    This appears to be an ASP.Net MVC question, unless I am mistaken, so I am going to move it to the correct forum.

    Thanks

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width