Calling another different view from the controller using ASP.NET MVC 4

Related searches

I have a view (Index.cshtml) with a submit button. When the submit button is clicked, it calls an action (Action01) within the controller (TestController.cs) so at the end of the action I want to return to the caller (Index.cshtml) view with a custom view model as a parameter. How do I do this?

Results after first attempt using View("ViewName",model):

An error is raised, as the action is within the controller Test, so returning, it is searching for \Views\Tests\Index, and my Index page is in \Views\Home\Index.

The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:

~/Views/Test/Index.aspx
~/Views/Test/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Test/Index.cshtml
~/Views/Test/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Final solution:

I have used return View("ViewName", model), and I have changed my directories structure as it was the problem.

You can directly return a different view like:

return View("NameOfView", Model);

Or you can make a partial view and can return like:

return PartialView("PartialViewName", Model);

how to call another view with parameter from controller in mvc 4 , Calling another different view from the controller using ASP.NET MVC 4 - asp.net -mvc. ASP.NET Forums / General ASP.NET / Getting Started / how to call another view with parameter from controller in mvc 4 how to call another view with parameter from controller in mvc 4 [Answered] RSS 4 replies

To return a different view, you can specify the name of the view you want to return and model as follows:

return View("ViewName", yourModel);

if the view is in different folder under Views folder then use below absolute path:

return View("~/Views/FolderName/ViewName.aspx");

View components in ASP.NET Core, Hi,. Thanks for your post.But where is the parameter passing in the calling of view ?I want to http://stackoverflow.com/questions/11772072/mvc-calling-a-view- from-a-different-controller � http://forums.asp.net/t/1765073.aspx? Calling another different view from the controller using ASP.NET MVC 4 Hot Network Questions Why exactly does Curiosity's RTG make more electricity on cold days?

You have to specify the name of the custom view and its related model in Controller Action method.

public ActionResult About()
{            
   return View("NameOfViewYouWantToReturn",Model); 
}

Part 3, add a view to an ASP.NET Core MVC app, This article was written using controllers and views, but view You can specify a different view name when creating the view For ASP.NET Core 1.1 and higher, you can invoke a view component as Mvc; using Microsoft. ASP.NET MVC: Call method in another namespace / area. 18. Calling another different view from the controller using ASP.NET MVC 4. 3. MVC4 RedirectToAction returns

            public ActionResult Index()
            {
                return View();
            }


            public ActionResult Test(string Name)
            {
                return RedirectToAction("Index");
            }

Return View Directly displays your view but

Redirect ToAction Action is performed

asp net mvc 5 return view from another controller Code Example, NET Core MVC app. 08/04/ They provide an elegant way to create HTML output with C#. The preceding code calls the controller's View method. For example, if you select the Privacy link, the The Layout property can be used to set a different layout view, or set it to null so no layout file will be used. Passing Data From One Controller To Controller In ASP.NET MVC Using TempData Tune in FREE to the React Virtual Conference Sep. 11 at 10am ET x LEARN: React Virtual Conference

Also, you can just set the ViewName:

return View("ViewName");

Full controller example:

public ActionResult SomeAction() {
    if (condition)
    {
        return View("CustomView");
    }else{
        return View();
    }
}

This works on MVC 5.

C# queries related to “asp net mvc 5 return view from another controller”. c# call another controller view in mvc � c# mvc return view from different controller � how to return another view from controller � mvc return view to another controller if it is disabled in your browser. INSTALL GREPPER FOR CHROME� Part 6, controller methods and views in ASP.NET Core. 12/13/2018; 9 minutes to read +12; In this article. By Rick Anderson. We have a good start to the movie app, but the presentation isn't ideal, for example, ReleaseDate should be two words.

ASP.NET MVC: Unit testing controllers that use UrlHelper Call one constructor from another Calling another different view from the controller using ASP.NET MVC 4

Choose ASP.Net MVC project from template and Press Next, then name the empty project as RoutingExample and click ok. Step 2: Add two controllers. I have added Home and Second in this example. Step 3: Add this snippet in Index action of Home Controller to redirect to Second Controller action Index. Step 4: Choose default controller Home and

How to Call Another Controller View Using ActionLink In ASP.NET MVC Filed Under: ASP.NET , MVC on 9 Sep 2015 compilemode.com In this article we will learn how to Call Another Controller View Using ActionLink In ASP.NET MVC.

Comments
  • An error is raised as action is in a controller whose view it is under \Views\Test
  • I have modified my directories structure. It was the problem. Now your solution works like a charm. Thanks a lot! My accepted solution is yours as you have answered first.
  • My intellisense in VS2013 wasn't picking this method up, even though it seemed like it should have been there, so this is great. Thanks. Even when I tried it, it didn't pick it up until I saw your answer and typed the entire thing out. Thanks.
  • you will have to use absolute path will returning view from diffrent folders. see update code.