Razor _layout.cshtml Have A Leading Underscore In File Name?
Jan 2, 2011
In the default ASP.NET MVC 3 project, layout & partial cshtml files start with an underscore (eg. _viewstart, _Layout, _LogOnPartial). Why? Does the framework give some special meaning to a cshtml file that begins with an underscore?
I have a MVC3 project using Area in it.the struct of web site si ' top - middle - bottom'the middle layer is divided into left and right partat the left part , I want to write codes as public to use, but '_ViewStart.cshtml' in the Area it's point to the '_Layout.cshtml' file at '~/Views/Shared/' my problem is how to use another cshml file as '_Layout.cshtml'
In my application users can write their own 'templates'. That are filled with data from other sources. I could use a simple token replacement, but I would like to be able to use the Razor syntax and engine for rendering the template. Here is an overly simplified example:
[Code]....
Before you point to the following sources I will clarify what I have learned from them:RazorEngine (http://razorengine.codeplex.com/). This code compiles the string into a class, then a dll, then finally reads from a dll - all this to bypass the MVC engine. I don't want to do that because I am in MVC and don't want the additional overhead.The following blog shows how to do this for one of the MVC 3 pre-releases:http://buildstarted.com/2010/09/28/mvc-3-razor-view-engine-without-a-controller/ I cannot get it to work with MVC 3 RTM. When I take the exact code (and replace the CshtmlView with a RazorView) I end up with the error: The method or operation is not implemented. It appears to have something to do with @Model.Name, and being unable to find "Name".A comment in the blog elludes to a statement from ScottGu that the RTM would allow this functionality from the get go. I cannot find this blog.
I'm attempting to access a layout page in an MVC page like this:
[Code]....
The problem is that I get this error:
he layout page "/Shared/_Layout.cshtml" could not be found at the following path: "/Shared/_Layout.cshtml".
Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: The layout page "/Shared/_Layout.cshtml" could not be found at the following path: "/Shared/_Layout.cshtml".Source Error:
[Code]....
Stack Trace:
[Code]....
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Not sure why this is a problem, I was referencing this page:
This question appear when I worked with partial view (MVC3/Razor), but I am sure - it's clear Razor Syntax question, not related direct to partial view. So - I have partial view Menu.cshtml with full markup as:
@model IEnumerable<SportsStore.WebUI.Models.NavLink> @foreach(var link in Model) { @Html.RouteLink(link.Text, link.RouteValues); }
No problem - "parent" view call it @{Html.RenderAction("Menu", "Nav");} and all work as magic. But, if I will edit the Menu.cshtml as:
@model IEnumerable<SportsStore.WebUI.Models.NavLink> @foreach(var link in Model) { Html.RouteLink(link.Text, link.RouteValues); }
(see - NO '@' before Html.RouteLink!) all just broke: now @{Html.RenderAction("Menu", "Nav");} output is totally empty, no one HTML tag. Want to know - what is the difference between two piece of code? I assume @ before foreach also automatically "drop into" and apply to Html.RouteLink as well? So - am I wrong?
I manage a large asp.net site which has previously been converted from static html site to asp.net. For several reasons (mainly SEO) we decided not to rename all the files to .aspx back when we originally converted the site. This was very easy to do by simply adding the buildProvider and httpHandler to the web.config.
Now I am upgrading the site to use Asp.net WebPages with Razor cshtml files. I can rename all the files if necessary, and use url rewriting to make the urls stay the same, however it would be much easier if I could just configure the web.config to tell it to parse .html files as if they were .cshtml. I have searched around quite a bit, and could not find anything equivalent to the PageHandlerFactory for razor pages. It appears as though it is just an internal mechanism in the .net 4.0 ISAPI handler.
The site is currently running on Windows 2003 server and IIS 6. We will be upgrading to 2008/IIS 7.5 in the near future, but I'd prefer not to wait for that. Is there any way to get the .html files to be parsed by razor as if they were .cshtml files?
here is the pagehttp://www.avakian.gr/Default3.aspx?categorysID=111&parentCategoryID=1&products=aunder the product image is the same product in different views inside a repeaterut this underscore character is annoying
I'm new to MVC asp.net and we are developing a intranet based application we have a ms access as our datase. how can I use this? I'm following some tutorial and it's use a mdf file. Is there a possibility to use ms access? how to configure the web.config to use a mdb files with password.
Im currently using a method that looks like the following code to add script and css files to the head of the Layout file.
[Code]....
My problem is that this is a static method meaning it persists the list of stylesheets and script files.
I need to do the same thing that this does but without keeping it persistant.
I need the lists to be remade on every request since they change from page to page what the look are on that specific page.
Is it possible to clear the lists on every request prior to adding the scripts that are needed or maybe after they have been rendered out?
Update:
The reason for not using a section, RenderPartial or RenderaActions is to prevent the same stylesheet or script file to be added more than once to the Layout file.
The site im building has a Layout_.cshtml with the basic layout. This in turn is used by a View that loops through a list of items and for each item a RenderAction is called that outputs the specific partial view for that item. These partial views sometimes need to add stylesheets and scripts.
As there can be needed to add many different scripts and stylesheets from different partial views a global list for styles and scripts were the only way i thought this could be done so there is a global place to check if a script is allready added to the collection or not and then render them all at once in the order they were added.
Update 2:
The real question is how to do the same kind of function (a global list) but without using a static Extension method.
i have a asp.net web site with it we have admin area with login page for admin only and all site is allowed for all - i need to ask how to define the right security configuration for it as i get this error Cannot use a leading .. to exit above the top directory. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the codeAn unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
I'm currently having an issue with asp net mvc and iis7 rewrite module. I'm rewriting a page from /kw.htm to /Listing/Search. And when it renders I have an exception that says "Cannot use a leading .. to exit above the top directory" I thought this scenario was now handle with the iis7 rewrite module. Did I miss something ?
I have understood there is no way to keep leading zeros in a OleDbDataAdapter?
Im trying to read some data from a text file with:
MyCommand = New System.Data.OleDb.OleDbDataAdapter("SELECT F7, F5, F9, F1 FROM " & System.IO.Path.GetFileName(bonnerfil.PostedFile.FileName), MyConnection)
I have managed to keep leading zeros if I add a Schema.ini file into the directory with column set to Char.
But, when having a Shema.ini the select statement reads from start to end of the file. As you see in my select statement I prefer/must have the coulumn 7 first being read and so on. This do work and I will have get the result I want. But for now it´s either - get the order of columns correct or have leading zeros.
how can I either have a Schema.ini that reads the file in the order I want, or keep leading zeros and not have the order I want.
The GridView in ASP.NET 2.0 is trimming the leading spaces from data coming from a SQLServer database. I have yet to find a way to keep it from doing that. The data in this particular view is being edited to remove such spaces, but only upon editing the row can any leading spaces be seen, meaning, at present, each row will have to be touched. With 12,000+ rows, that's a little much.
What little I've found on Google has mainly be concerned with trimming leading spaces. Is there a way to force GridView to show the data exactly as it is in the database, leading spaces and all?
I am using a master page and I need to change how the <title> element is rendered. The <title> content renders as expected. The problem is the whitespace that bounds my <title> element. I want to get rid of it.How do I remove the leading and trailing characters
I have a string coming from a stored procedure looks like '001234567'.
sqlCommand = new SqlCommand("csp_Bbp_OBN_GetBasePageList", BBConnection); sqlCommand.CommandType = System.Data.CommandType.StoredProcedure; sqlCommand.Connection.Open(); // Run the SQL statement, and then get the returned rows to the DataReader. accReader = sqlCommand.ExecuteReader();............
In my case, from the stored procedure I am returning the varchar, after executing and reading it I am getting the value to basePage.GrouNum which is a string. So, I don't see where it is trimming the leading zeros.
Example: GroupNumber in the table is : "001234567" BasePage.GroupNum after reading from DataReader : "1234567"
But, I do not want the leading zeros being trimmed.
I have a formview which binds to a table where one of the fields is an integer zip-code field. I want to pad the zip with a leading zero in the edit template when the zip is something like "02134". How do I edit the bound data without "breaking" the two-way binding?
I wrote simple function to add the zero and return a string:
Public Function padZIP(ByVal zip As Integer) As String Dim tmpStr As String = CType(zip, String) If tmpStr.Length = 4 Then tmpStr = "0" & tmpStr Return tmpStr End Function
I have two textboxes and a CompareValidator attempting to ensure that TextBox_1 contains a date that comes on or before the one in TextBox_2. When one textbox contains a date in "MM/dd/yyyy" format, and the other uses "M/d/yyyy", and the only difference between the two is a leading zero in the "MM" part, my validator fails to recognize that the dates are equal.
I've solved the problem by using the same format for both, but I'm wondering what's going on.
(I'd post the code, but there are so many layers -- controls using inherited classes, etc. -- that it would be more than a bit difficult to make sense out of ...)