Reputation: 12928
I have a controller with a method that points to a view. How do I change the view that the action is mapped to? Like I want it to call ViewB instead of ViewA? Where do these mappings exist and how can I modify them? Thanks for any tips.
Thanks,
~ck in San Diego
Upvotes: 4
Views: 3354
Reputation: 2077
You can do the default:
return View(myModel);
Or specify the View Name under the same controller view folders or in shared:
return View("ThatView", myModel);
Or whatever view:
return View("~/myfolder/WhatEverView.ascx", myModel);
Upvotes: 1
Reputation: 2065
You could also return a RedirectToAction("View")
, or with Javascript
json(new { Redirect = url.Action(action, data) }, JsonRequestBehavior.AllowGet);
and handle the return appropriately on the client side.
Happy Hunting!
Upvotes: 2
Reputation: 5021
You can pass the view name into the View
method: http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.view.aspx
Upvotes: 1
Reputation: 24754
Instead of:
return View(someModel);
use
return View("ViewYouWant", someModel);
Upvotes: 8
Reputation: 100567
To have a controller method redirect to a view that's not named the same as the action method, you can change the statement from
return View();
to
return View("ViewB");
Upvotes: 7