ASP.NET MVC How to point a controller action to another view?

I have a controller with a method that points to a view. How to change the view on which the action is mapped? How do I want it to call ViewB instead of ViewA? Where do these mappings exist and how can I change them? Thanks for any advice.

Thank you
~ ck in San Diego

+3
source share
5 answers

Instead:

return View(someModel);

using

return View("ViewYouWant", someModel);
+7
source

In order for the controller method to be redirected to a view that is not named in the same way as the action method, you can change the operator from

 return View();

to

 return View("ViewB");
+7
source

RedirectToAction("View") Javascript

 json(new { Redirect = url.Action(action, data) }, JsonRequestBehavior.AllowGet);

.

!

+2

You can pass the name of the view to the method View: http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.view.aspx

+1
source

You can do the default setting:

return View(myModel);

Or specify the name of the view in the same folders for viewing the controller or shared:

return View("ThatView", myModel);

Or any kind:

return View("~/myfolder/WhatEverView.ascx", myModel);
+1
source

Source: https://habr.com/ru/post/1775754/


All Articles