I have no idea why this error is occurring after debugging the project even though the codes are default.
Controller
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
View
#{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<div>
Hi
</div>
</body>
Somehow or rather, after debugging, the Requested URL is always /Views/Home/Index.cshtml but accessing Home via browser is fine. (http://localhost:58323/home)
I googled and solution hints that the problem lies in global. But thats weird, I dont remember making any changes to it.
Global
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
Appreciate any help. Thank you
I think you just have your visual studio settings set so that the view is set to the start page. Right click on the project and go to properties, then to the web tab. Is the 'specific page' radio button selected with 'Views/Home/Index.cshtml' set as the value? Change it to use a start url. Personally I prefer not to have the debugger start up a browser and use Don't open a page.
Right click your web project -> Properties -> Web
check that you have the start action set to Specific Page with no value in the field.
My guess is that you have the start action set to current page.
This error might even cause if the hierarchy of the folder structure is incorrect in Views folder.
If you are adding views by right-click on Views folder.The new view added might be incorrectly placed in the folder hierarchy.
The way to troubleshoot the problem is:
Consider a view named index.ascx which is supposed to be linked to a Controller named HomeController.
Under the Views folder there should be a folder name Home (relating to the Controller) and the
index.ascx should reside in Home folder.
The best possible way to add view is to right-click just beside the public method which will show a Create View option in context-menu.If you crate view in such manner then folder hierarchy is automatically created.
Related
I know how to display default view in Code Igniter. But, how can I access other files inside view folder. Example I want to display 'application/views/admin/index.php' but it isn't default view.
You can add sub folders in view like so.
$this->load->view('admin/index');
Is that what your meaning.
Codeigniter Views
File name: Example.php
<?php
class Example extends CI_Controller {
public function index() {
$this->load->view('admin/index');
}
}
Folder Structure
application
application / views /
application / views / admin
application / views / admin / index.php
I would not choose index.php for a name for a view I would rename it to another name dashboard.php or some thing. Because you have a index.php in the main directory.
I'm using MVC and having trouble figuring out how to hide the controller and action in the URL.
I have seen many things on how to hide the controller or the action but most are not for the default controller.
My controller looks like this:
routes.MapRoute("Default",
"{controller}/{action}/{id}",
new{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
});
When you navigate to my site the URL looks like this:
www.mysite.com/Home/Index
I need it to hide the "Home" and "Index" so it looks like this:
www.mysite.com
I have the default route as the last route in the routeConfig file. Any help would be appreciated.
Is this your root URL. If so than use the following code in your routes.rb file.
root "home#index"
then you will get the www.mysite.com
However, there are many techniques to hide the controller and action from the url. Please have a look on this post rails remove controller path from the url
I am facing strange behaviour for _Layout.cshtml
I have created a _Layout.cshtml for my project, it's working fine for Default rout i.e /Home/Index
then I have another controller named Biz wth action Categories, when I create the view for it using _Layout and run the project
all the content was displayed without any style and URL in the browser was localhost:54124/Biz/Categories.
when I configured rout in RouteConfig.cs file
as
routes.MapRoute(
name: "DT_FAP_Default",
url: "Categories",
defaults: new { controller = "Biz", action = "Categories", id = UrlParameter.Optional }
);
the layout is working fine
anybody have idea, what i am missing here?
I don't want to configure route for each action as my project has too many actions
Am facing same issue for other projects too. do I need any global configuration for vs?
finally, I found the solution
I changed the css linking code
Old:
<link id="layout-theme" rel="stylesheet" type="text/css" href="~/assets/themes/dark-blue.min.css" />
New:
<link id="layout-theme" rel="stylesheet" href="#(Url.Content("~/assets/themes/dark-blue.min.css"))" />
I am using rails 3.2.12 version.
I want to embed HTML5 game in my static web page (game.html.erb).
I am confuse about what will be the src of Iframe tag?
I am using
<pre>
iframe src="index.html" height="460" width="500"
</pre>
in game.html.erb page
but error occurs
NO ROUTE MATCHES GET "/static_pages/index.html"
I have put game file index.html in same folder as game.html.erb.
what is issue?
If the html is static then just move the html file into the '/public' folder of your rails app and change the src for the iframe to be "/index.html"
If you don't want to put it into the public folder, you'll need to either add an action to the controller that your game.html.erb is rendered from or create a separate controller for the static html.
Based on what your question states though, I would put it into the public folder as it is just static html and wouldn't require a controller.
The problem with the setup you have is that your index.html file is just a static file, where the view folder that contains game.html.erb relates to a controller and is rendered from an action in the controller. Static files don't get rendered from that folder. The public folder contains static files and folders that you want on the root of your site (except for javascript, images and css which go in the asset pipeline).
I known There is a default _Layout.cshtml file in Asp.net MVC just like MasterPage in Asp.net Web Site. Can I define multiple layout templates in my MVC app? If so ,How to make it? Please give me some code example . Thanks.
You can create multiple Layout pages and use it in differnt views. You may mention the new layout pages inside your views by mentioning the Layout property in your views.
Create a new View and name it as _AdminLayout.cshtml under Views/Shared folder. You may create your HTML markup for your master page template there. Make sure you have #RenderBody() section in your Layout page so that the content of your normal views will be replaced here when it renders.
<html>
<head>
</head>
<body>
<h1>My new Layout</h1>
#RenderBody()
</body>
</html>
And if you want to use this Layout in a view, you can do it like this
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<p>The content here will be present inside the render body section of layout</p>
If you want to use the new Layout for all the Views by default without explicitly mentioning like the above code, you can do it in the Views/_ViewStart.cshtml file
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}