razor

Difference between MVC 3 Partial Page (Razor) and MVC 3 View Page with Layout (Razor) ?

In MVC 3 Beta, is there a difference between the templates MVC 3 Partial Page (Razor) and MVC 3 View Page with Layout (Razor) ? I added a partial page (_partialList) to my application. Now when I return only the partial view, it applies the Layout present in _ViewStart.cshtml - acting very much like a stardard view page with layout. ...

Difference in Forms Authentication between Razor Preview and Razor Beta?

I'm attempting to upgrade an MVC project to Beta using Razor (from the Preview release) and am now experiencing strangeness with Razor not going to my login view that it use to go to (when someone asks for an action that required authorization). My web config has <authentication mode="Forms"> <forms loginUrl="~/Account/LogOn" tim...

What's the base class of a Razor View in ASP.NET MVC3

I'm trying to have all my views inherit from a custom class so that I can add certain behaviour and values to all pages, but I'm having some issues. I tried subclassing System.Web.Mvc.WebViewPage but I'm forced to implement an Execute procedure that I don't know what it should do. Also, if I try to access the Context variable, I get a nu...

Asp.net MVC Razor - Custom javascript inside if block

How can I put javascript code inside if block. @{ #if DEBUG $("#User").val("JDoe"); $("#Password").val("secrect"); #endif } When I try above code I get this compiler error: Compiler Error Message: CS1056: Unexpected character '$' And if I change $ to jQuery: Compiler Error Message: CS0103: The name 'jQuery' does no...

Where should I place Declarative HTML helpers in ASP.NET MVC 3

I'm trying to make a declarative HTML Helper as specified in ScottGu's Razor post, but I'm not having much luck. I tried putting a Helpers.cshtml file with a DateTimeHelper in Views/Helpers but it wouldn't pick it up, so I tried in App_Code as per the MVC 3 Beta post. Now it picks it up, but when I try to use it in a file like so: @Date...

ASP.NET MVC: logic in _layout.cshtml that takes variables from a given controller

Hi all, New to MVC so forgive me if the terminology is a little off. I'm using ASP.NET MVC3 beta and VS 2010. I'm not sure if this is an error of concept, of syntax, or what. Essentally, what I'd like to do is, for _layout.cshtml, I would like to include the jQuery script for any Controller whose ActionResult sets ViewModel.UseJQuer...

Webmatrix, Razor, and Sessions

Hi all, I'm getting some funky behavior with session variables with Razor .cshtml pages. Essentially on some pages I check to see if a Session variable is set, and if not I set it. I keep getting a null object reference. I believe this is because ultimately Razor is designed for MVC, and I did a little reading about the MVC life cyc...

Using Razor View Engine within JavaScript

Using the new ASP.NET MVC 3.0 Razor View Engine, is there any way to call upon it within javascript code? In the normal view engine, you could do something like ... <script type="text/javascript"> $(document).ready(function() { function somejQueryFunction(obj) { <%= obj.ExecuteSomething() %> } }); </script>...

Modify the Template Helpers MasterPage with Razor

I am using the new Razor view engine with ASP.NET MVC and would like to know how to modify the editor template master page in a similar way to how it is done in this blog post. Is there any examples on how to do this with Razor? ...

How do I add the css class attribute to a textbox in razor?

I have tried: @Html.TextBoxFor(m => m.UserName, new {@class='textbox'}) which isn't working. ...

ASP.NET MVC DropDown Editor Template

I am looking for the best method for creating a drop down list editor template with MVC. There seem to be various methods but I can't find any method that is best, everyone seems to do it differently. I am using MVC3 with Razor as well, so a method that works with this is preferred. ...

Does Razor syntax provide a compelling advantage in UI markup?

I notice Scott Guthrie is starting to mention Razor a fair bit on his blog but I'm just not that sure that it's a good fit for my style. Granted it's a fairly unfamiliar style for someone who's pretty used to a "standard" sort of ASP.Net markup (content place holders and inline code), but it just feels like a lot of additional pages to ...

Using Knockout.js with newest jQuery Files and ASP.NET MVC

I am attempting to use Knockout.js with ASP.NET MVC 3.0 (Title gave it away, didn't it?!) http://knockout.js.com I am running into some problems (more related to the new jQuery Tmpl Engine than ASP.NET MVC 3.0). I am using Steve Sanderson's Example Program in my test, and have mostly replicated his results with the new Razor View Engi...

ASP.NET MVC Razor - Linkshare - Increase Image Size

Hello, I just downloaded the Microsoft.Web.Helpers package from nupack and added linkshare to my site using @Linkshare.GetHtml() syntax. It works extremely well - except the icons for social sites are tiny. Does anyone know of any way to increase these to a larger size? Looking at the API I don't see anything but perhaps there is someth...

Creating an object.cshtml editor template with MVC and Razor

I am looking to create an editor template for Object.cshtml to change the behavior of the Html.EditorForModel() method. I can't find any example of this using Razor. I have seen this example using MVC2 and WebForm view engine but don't know enough about razor to convert it. Even a simple example would be very helpful. ...

Using html helpers in Razor web helper

I am trying to create a razor web helper something like this @helper DisplayForm() { @Html.EditorForModel(); } But this gives the error "CS0103: The name 'Html' does not exist in the current context". Is there any way to reference html helpers within web helpers? ...

How to add reference to a dynamic assembly for compiling another dynamic assembly?

In my AppDomain there are few dynamic assembly, when I try codeDom.CompileAssemblyFromSource to Compile another new assembly, I can't figure out a way to add those dynamic assemble to ReferencedAssemblies. foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { compilerParameters.ReferencedAssemblies.Add(assembly.L...

Razor Syntax and Javascript...

Hi, As a test I'm converting a proof-of-concept app we've written from Web Forms to Razor, simply so we can evaluate it. I've run into one problem so far that's making my head hurt..generating client-side Javascript... Web-Forms <script type="text/javascript"> var jqGridIdList = "<%: Url.Action ("getidlist", "office", new { area ...

Render partial view with dynamic model in Razor view engine and ASP.NET MVC 3

When I try to render a partial view whose model type is specified as: @model dynamic by using the following code: @{Html.RenderPartial("PartialView", Model.UserProfile);} I get the following exception: 'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'RenderPartial' but appears to have an extension method by tha...

How to set a Razor layout in MVC via an attribute filter?

I'd like to set a default Razor layout via code in either a base controller or an attribute. It was mentioned in the Docs that this is possible, but I can't figure out how it's done. I know there's the masterPage parameter to the View method available, but I would like all views returned by a controller to have this value set automatica...