Questions tagged [razor-2]

Razor 2 is an upgrade of a template language used by ASP.NET Web Pages and ASP.NET MVC (since version 3), packaged with ASP.NET MVC 4.

Razor 2 is an upgrade of a template language used by ASP.NET Web Pages and ASP.NET MVC (since version 3), packaged with ASP.NET MVC 4. It supports seamless transitions between HTML markup and C# or VB.NET code. Transitions between markup and code are indicated by the "@" sign.

Razor is what Microsoft is calling a "code-focused templating approach". This would put it in the same category as WebForms, ERB, Smarty, velocity and many others. Other template engines, such as Spark or HAML are more declarative.

460 questions
66
votes
4 answers

ASP.NET MVC 4 override emitted html name and id

I'm trying to change the emitted name of the html input created by @Html.HiddenFor. The code I'm using this: @Html.HiddenFor(e => e.SomeProperty, new { @id = "some_property", @name = "some_property" } Now this works for the id, however it doesn't…
Anemoia
  • 7,928
  • 7
  • 46
  • 71
44
votes
9 answers

How to add a script in a partial view in MVC4?

This is the code which I have in my partial view @model Contoso.MvcApplication.Models.Exercises.AbsoluteArithmetic @using(Html.BeginForm()) {
Darf Zon
  • 6,268
  • 20
  • 90
  • 149
35
votes
5 answers

Error 22 The "EnsureBindingRedirects" task could not be loaded from the assembly

I cloned a project with vs 2013. When I run it I get this error. Error 1 The "EnsureBindingRedirects" task could not be loaded from the assembly D:\BMaster\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.Tasks.dll. Could not load…
codegrid
  • 977
  • 2
  • 13
  • 33
32
votes
7 answers

Visual Studio 2015 Razor View MVC Types not recognized

I installed Visual Studio 2015 and rebooted. The "MVC" types are not recognized in 2015 but are still recognized in 2013. This is my "Views" web.config:
Justin
  • 609
  • 2
  • 10
  • 21
32
votes
8 answers

C# syntax to initialize custom class/objects through constructor params in array?

I have a class with minimum 4 variables and I have made a constructor for the class so that I can initialize it with MyClass testobj = new MyClass(1234,56789,"test text", "something else", "foo"); Works fine. Then I have an array of these, that I…
BerggreenDK
  • 4,915
  • 9
  • 39
  • 61
29
votes
1 answer

ASP.NET MVC 4 jQuery Validation Script Bundle Not Working

I have recentely upgraded a website to use ASP.NET MVC 4 and have the following code to render my jQuery validation bundle. But I get the following error: Microsoft JScript runtime error: Object doesn't support property or method 'live' And this…
Alex Hope O'Connor
  • 9,354
  • 22
  • 69
  • 112
25
votes
2 answers

MVC4 Razor difference in @model and @inherit in view header?

To make a view strongly typed we can use @model and @inherit. Can you please tell me what the difference is between both of them? Edit: Please see this example.
user576510
  • 5,777
  • 20
  • 81
  • 144
22
votes
1 answer

How do you define a layout for specific areas in ASP.Net MVC 4?

I'm playing a little catch up here as I went straight from MVC2 to MVC4, so learning Razor and everything else all at once. I'm using an admin area in this new application, and I noticed when I went to the controller in the admin area it rendered…
Jhorra
  • 6,233
  • 21
  • 69
  • 123
21
votes
1 answer

Difference between @: and in Razor

What's the difference between these 2 in Razor? I find that I can accomplish the same, whether I use @: or .
anemaria20
  • 1,646
  • 2
  • 17
  • 36
21
votes
4 answers

RenderBody() and RenderSection() must be on every child layout?

I have three simple layout, _Layout.cshtml (this is the base layout) @RenderSection("something", required: false) @RenderBody() _Main.cshtml @{ Layout = "~/Views/Shared/_Layout.cshtml"; } @section something { Hey I'm actually on the _Main…
Okan Kocyigit
  • 13,203
  • 18
  • 70
  • 129
21
votes
4 answers

ASP.NET MVC 4 Script bundling causes errors upon deployment

My website is working fine on localhost when @Scripts.Render() is not bundling the scripts however when I deploy to my server the bundled Javascript must contain an error as all Javascript on my page stops working. Here is my bundle code: …
Alex Hope O'Connor
  • 9,354
  • 22
  • 69
  • 112
18
votes
2 answers

MVC and Entity Framework Html.DisplayNameFor with Composite ViewModel

I’m fairly comfortable with MVVM using WPF/Silverlight but this is my first attempt at an MVC Web Application…just an fyi for my background. I’ve created a controller called TestSitesController which was auto generated from from the “Site” model…
Dan P
  • 1,939
  • 3
  • 17
  • 30
18
votes
6 answers

MVC4 localization. Accessing resx from view

In my view I would like to access resource strings from the specific local resource on that file.. Just as you know it from web-forms: (string)GetLocalResource("Title"); Painless and smooth. The framework handles which .resx file to get from the…
Kasper Skov
  • 1,954
  • 10
  • 32
  • 53
16
votes
6 answers

Strange NullRefereneceException in Razor helper

I'm using Razor Helpers in a C# Web Forms application. The following code compiles and renders A-OK when called: @helper MemberListItem(string firstname, string lastname, string avatarUrl) {
  • @firstname @lastname …
  • Jonathan Wilson
    • 4,138
    • 1
    • 24
    • 36
    16
    votes
    6 answers

    How to get sequence/array index in Editor Template?

    Case: I have a list of items of Class X displayed using Editor Template for Class X. Problem: How can I get index of an item being processed on the inside of the Editor Template?
    Andrei
    • 4,122
    • 3
    • 22
    • 24
    1
    2 3
    30 31