I have the following layout for my mvc project:
However, when I have this for DemoArea1Controller
:
public class DemoArea1Controller : Controller { public ActionResult Index() { return View(); } }
I get the "The view 'index' or its master could not be found" error, with the usual search locations.
How can I specify that controllers in the "Demo" namespace search in the "Demo" view subfolder?
You can use the RedirectToAction() method, then the action you redirect to can return a View. The easiest way to do this is: return RedirectToAction("Index", model); Then in your Index method, return the view you want.
By default Razor Pages are stored in Pages folder under project root.
ASP.NET MVC does not use ViewState in the traditional sense (that of storing the values of controls in the web page). Rather, the values of the controls are posted to a controller method.
Right click on controller Folder and select template Empty MVC controller. Right click on Index method and select Strong -typed view as shown in the following figure. In above code I have two html radiobutton and one html text box and simple submit Button. Press F5 and run you application.
You can easily extend the WebFormViewEngine to specify all the locations you want to look in:
public class CustomViewEngine : WebFormViewEngine { public CustomViewEngine() { var viewLocations = new[] { "~/Views/{1}/{0}.aspx", "~/Views/{1}/{0}.ascx", "~/Views/Shared/{0}.aspx", "~/Views/Shared/{0}.ascx", "~/AnotherPath/Views/{0}.ascx" // etc }; this.PartialViewLocationFormats = viewLocations; this.ViewLocationFormats = viewLocations; } }
Make sure you remember to register the view engine by modifying the Application_Start method in your Global.asax.cs
protected void Application_Start() { ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new CustomViewEngine()); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With