Skip to main content

Questions tagged [razor]

Razor is a template language used by ASP.NET Web Pages, ASP.NET MVC (since version 3), and ASP.NET Core. It adds a layer of abstraction above HTML generation. It supports seamless transitions between HTML markup and C# or VB code. Transitions between markup and code are indicated by the "@" sign.

83 votes
2 answers
14k views

Post an HTML Table to ADO.NET DataTable

I have a HTML table as below in my View: <table id="tblCurrentYear"> <tr> <td>Leave Type</td> <td>Leave Taken</td> <td>Leave ...
RKh's user avatar
  • 14k
9 votes
2 answers
11k views

Pass List of Checkboxes into View and Pull out IEnumerable [duplicate]

I have a list of items that will be associated to a user. It's a one-to-many relationship. I want the entire list of items passed into the view so that they can choose from ones that are not ...
muttley91's user avatar
  • 12.5k
10 votes
3 answers
13k views

MVC5 Razor html.dropdownlistfor set selected when value is in array

I'm developing an ASP.NET MVC 5 application, with C# and .NET Framework 4.6.1. I have this View: @model MyProject.Web.API.Models.AggregationLevelConfViewModel [...] @Html.DropDownListFor(m => m....
VansFannel's user avatar
  • 45.6k
470 votes
13 answers
447k views

Using Razor within JavaScript

Is it possible or is there a workaround to use Razor syntax within JavaScript that is in a view (cshtml)? I am trying to add markers to a Google map... For example, I tried this, but I'm getting a ...
raklos's user avatar
  • 28.4k
298 votes
26 answers
437k views

How to get the Display Name Attribute of an Enum member via MVC Razor code?

I've got a property in my model called Promotion that its type is a flag enum called UserPromotion. Members of my enum have display attributes set as follows: [Flags] public enum UserPromotion { ...
Pejman's user avatar
  • 3,914
682 votes
16 answers
311k views

Escape @ character in razor view engine

I am creating a sample ASP.NET MVC 3 site using Razor as view engine. The razor syntax starts with @ character e.g. @RenderBody(). If I write @test on my cshtml page it gives me parse error CS0103: ...
ajay_whiz's user avatar
  • 17.9k
161 votes
12 answers
64k views

Dynamic Anonymous type in Razor causes RuntimeBinderException

I'm getting the following error: 'object' does not contain a definition for 'RatingName' When you look at the anonymous dynamic type, it clearly does have RatingName. I realize I can do this with ...
JarrettV's user avatar
  • 18.9k
384 votes
23 answers
251k views

Injecting content into specific sections from a partial view ASP.NET MVC 3 with Razor View Engine

I have this section defined in my _Layout.cshtml @RenderSection("Scripts", false) I can easily use it from a view: @section Scripts { @*Stuff comes here*@ } What I'm struggling with is how ...
tugberk's user avatar
  • 58.2k
786 votes
12 answers
331k views

How do I import a namespace in Razor View Page?

How to import a namespace in Razor View Page?
Amitabh's user avatar
  • 60.5k
204 votes
9 answers
222k views

Mix Razor and Javascript code

I'm pretty confused with how to mix razor and js. This is the current function I am stuck with: <script type="text/javascript"> var data = []; @foreach (var r in Model.rows) ...
Kyle Brandt's user avatar
  • 27.9k
112 votes
8 answers
90k views

Using sections in Editor/Display templates

I want to keep all of my JavaScript code in one section; just before the closing body tag in my master layout page and just wondering the best to go about it, MVC style. For example, if I create a ...
eth0's user avatar
  • 5,087
342 votes
6 answers
108k views

ASP.NET MVC View Engine Comparison

I've been searching on SO & Google for a breakdown of the various View Engines available for ASP.NET MVC, but haven't found much more than simple high-level descriptions of what a view engine is. ...
mckamey's user avatar
  • 17.5k
46 votes
5 answers
32k views

Cascading drop-downs in MVC 3 Razor view

I am interested in how to implement cascading dropdown lists for addresses in a Razor view. My Site entity has a SuburbId property. Suburb has a CityId, and City has ProvinceId. I would like to ...
ProfK's user avatar
  • 50.5k
62 votes
8 answers
127k views

How can I use a reportviewer control in an asp.net mvc 3 razor view?

I'm trying to use a reportviewer control, within a razor view, in the mvc 3 framework. The online documentation talks of drag and drop. Any suggestion on how to insert it into the view.
Arun's user avatar
  • 1,639
6 votes
2 answers
6k views

How can I trigger/refresh my main .RAZOR page from all of its sub-components within that main .RAZOR page when an API call is complete?

I am working on an app that lets users search our database. When a user enters search terms, the app hits an API endpoint, and returns the data. I then display the data. When the API returns the data, ...
Brian's user avatar
  • 1,909

15 30 50 per page
1
2 3 4 5
215