MVC :: Running A String Through The Razor Engine Instead Of A Cshtml File?

Mar 29, 2011

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.

View 10 Replies


Similar Messages:

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?

View 4 Replies

MVC 3 Razor Syntax - Partial View Menu.cshtml With Full Markup

Mar 27, 2011

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?

View 2 Replies

Is It Possible To Use Razor View Engine Outside

Sep 2, 2010

If I look at the Razor View Engine, then I see a very nice and concise syntax that is not particularly tied to generating html. So I wonder, how easy would it be to use the engine outside asp.net in a "normal" .net environment for example to generate text, code,...

View 3 Replies

Can Server .html Files Using Razor As If They Were .cshtml Files Without Changing The Extension Of All My Pages

Feb 24, 2011

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.

<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
<httpHandlers>
<add path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>

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?

View 2 Replies

MVC :: How To Create Partial Views Using The Razor Engine

Jan 20, 2011

Using the Razor engine how do I create Partial Views. Do I create a normal View and calling the PartialView() in the controller will only output the body content and when calling View() in the controller will output the full page with layout. If not, do I need to create specific Partial Views and then use RenderPartial in the View.

View 6 Replies

Does The Razor View Engine Work For Mono

Nov 21, 2010

I tried searching a bit and didn't find an answer. Does the Razor View Engine work in Mono?

View 3 Replies

MVC :: How To Integrate Razor View Engine Into Web Application

Dec 21, 2010

How to integrate Razor view engine into mvc 2 web application?

View 3 Replies

MVC :: Razor View Engine - 'content' From DB Using VirtualPathProvider?

Dec 14, 2010

I'm working trying to realize a requirement where the pages should be 'configurable' at runtime (per client), stored in a database - a requirement that I have no say in Anyway, the current plan is to use the Razor view engine and 'load' the 'pages' dynamically. I have a basic sample working using a VirtualPathProvider and VirtualFile that serves up Raz'pages' on the fly.The question I have if there is a better approach when I have the Razor 'pages' stored in a dB (or any other repository)?

There seems to be some constraints and concerns when I check other postings. For example:'If a Web site is precompiled for deployment, content provided by a VirtualPathProvider instance is not compiled, and noVirtualPathProvider instances are used by the precompiled site.'
(from http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx )

View 1 Replies

MVC :: Razor View Engine And Add Namespace In Web.Config

Aug 22, 2010

I am working on a MVC project with Razor view engine and I have the following:

[Code]....

This only works if I have on the same view the following:

[Code]....

So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

View 4 Replies

MVC :: Create User Control Using Razor Engine?

Mar 8, 2011

How to create user control using razor engine?

*.ascx ==> old way, using aspx engine

View 1 Replies

MVC :: Does The Razor View Engine Support Generic Methods

Sep 3, 2010

Trying out the Razor view engine and for some reason my generic helper methods are breaking. For example:

public static class UrlHelperExtensions
{
public static string NonGenericHelper(this UrlHelper helper, Type controller)
{
return controller.Name;
}
public static string GenericHelper<TController>(this UrlHelper helper)
{
return typeof(TController).Name;
}
}

Works as expected:@Url.NonGenericHelper(typeof(ProjectEuler.UI.Models.Home))Breaks with the following exception:

@Url.GenericHelper<ProjectEuler.UI.Models.Home>()
"CS1502: The best overloaded method match for 'Microsoft.WebPages.WebPageUltimateBase.Write(Microsoft.WebPages.Helpers.HelperResult)'
has some invalid arguments"

The only workaround I could find is treating it as a "multi-token
statement":

@(Url.GenericHelper<ProjectEuler.UI.Models.Home>())

Not sure if this is the intended behavior or just a bug but it would be nice to be able to call a generic method as you would a non generic one.

View 2 Replies

Razor View Engine Intellisense Not Working VS 2010?

Feb 7, 2011

Inside VS 2010 I do not have any intellisense working. I have reinstalled everything and still nothing is coming up for intellisense?

View 2 Replies

Installing The Razor View Engine For Visual Studio?

Jul 14, 2010

I just downloaded and installed Web Matrix beta.

I am really liking the razor view engine.

Not so much the Web Matrix IDE.

Is there any way to install razor view engine for use in the Visual Studio without installing WebMatrix?

View 4 Replies

MVC :: Changing View Engine In Existing Project To Razor?

Nov 15, 2010

how do I change the view engine from aspx to razor in an existing project? If I just change the file extension to cshtml I always get "The controller for path '/path/About' was not found or does ..."

View 2 Replies

MVC :: Razor View Engine - How To Register The Partial Views In 3 Beta

Oct 15, 2010

On my projects I am using Razor View engine and I need to define custom Partial folders:

[Code]....

I had this because there was a problem in MVC 3 Preview. Was it corrected?

How should I register the Partial Views in MVC 3 Beta?

View 1 Replies

How To Use Razor View Engine Auto-complete To Work In A Class Library

Nov 11, 2010

We have a modular architecture where we have some views (cshtml) files in a separate project (class library). How can we get the syntax highlighting and autocomplete to work when the project isn't an MVC project?

note that the class library has controllers, views, models etc. It just doesn't have the web.config, global.asax, etc that a normal mvc project would have.

The intellisense works for everything but the so important model:

With MVC3 RTM, if you hover over the Model, you can now get a better error message:

[code]....

Then after adding the build provider, this error message appears:

[code]....

View 3 Replies

Adding A 3rd Party Test Framework For MVC3 And Razor View Engine?

Feb 19, 2011

Would like to add a third party test framework (such as NUnit or MbUnit) to the drop-down list of test projects for the ASP.NET MVC3 type project in Visual Studio 2010.

This had worked before for ASP.NET MVC2 and prior, but the msdn instructions are not accurate and does not work. Creating the registry keys in the HKEY_CURRENT_USER seem to delete the keys every time the VS-2010 starts, the HKEY_LOCAL_MACHINE does not follow the same tree structure.

how to add a third party framework under ASP.NET MVC3?

View 3 Replies

MVC :: Razor View Engine With ". NET Empty Web Application"?

Jan 18, 2011

point me in the direction of getting the Razor View Engine working correctly with an empty "non MVC" web application. I can correctly set it up with a MVC app or with a Web Site (Razor), but if I try and get it running with and empty app, I run into the following two problems:

1) I can't add new razor files to the application (*.cshtml files)

2) Once deployed to AppHarbor, the .cshtml files aren't found unless they have the extension specified (i.e. /Default won't work, but /Default.cshtml does)

View 3 Replies

WebMatrix :: How To Use C# Class From Cshtml File

Jul 19, 2010

I am new to ASP.NET, I would like to know how to create C# class in seperate file and using it in cshhtml file.

View 5 Replies

MVC :: Razor And String.Format Not Working?

Mar 3, 2011

I am trying the following:

[Code]....

Where @Resource.Info is "{0} - {1}".

But I always get <p>0</p> - <p>1</p>.

I tried a few more options like using @<text>, @Html.Raw but I always end up with an exception or the same result.

Basically I have a localized resource, @Resource.Info, and I need to insert in the phrase some htm code.

View 2 Replies

C# - Way To Use The Firefox (or Chrome Or Any Other Good Browsers) Rendering Engine To Convert Html (as A Text String) To An Image?

Jan 3, 2011

Is there a way to use the firefox (or chrome or any other good browsers) rendering engine to convert html (as a text string) to an image?I have full access to the server I'm using, so no limitations there.

View 2 Replies

C# - Task Based File Management Engine For .NET?

Mar 3, 2011

I need to implement task based file management engine. See picture:

So, I need to create Transformation Engine and Transformation rules parser. Does something like this already exist?

UPDATE

Input: Some files and metadata.

Output: Some of input files (maybe all, depends on rules) with another folder structure and file names. Xml files can be transformed with xslt to different text files.

View 2 Replies

Save Local File Path As String And Open File From Saved String?

Jan 29, 2011

I have a form where users can store some data for archived documents. All documents are ONLY in PDF format.

There are 2 things I would like to do:

1. there is a "file path" text box on the form. I would like to open a "browse file dialog" box when user clicks the textbox and then the user browses for the file (file is on the users local machine) and selects it. The full file path should be saved to the textbox as string (e.g. "c:archive2010document11122011.pdf"). Also I would like to "limit" the file browser dialog to only show PDF format files...

2. add a code behind command to open the file from the saved path+name (see 1.) in the user's default PDF viewer (Acrobat or Foxit)

View 11 Replies

MVC :: 3 Razor Using Mdb File With Password Instead Of Sql Server

Mar 17, 2011

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.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved