Questions tagged [razor]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
99 views

Display a table with exchange rate data

I have created a code that displays a table with exchange rate data. Have I used loops and conditions (if else) in a good way? ...
mariuszKen's user avatar
5 votes
1 answer
87 views

Display all files in a folder (object) along with nested subdirectories part 2

Previous post: Display all files in a folder (object) along with nested subdirectories Task: Given a main directory/folder, list all the files from it and if this directory contains nested sub-...
Alexander Lawaetz's user avatar
4 votes
1 answer
427 views

Display all files in a folder (object) along with nested subdirectories

Follow-up question: Display all files in a folder (object) along with nested subdirectories part 2 Task: Given a main directory/folder, list all the files from it and if this directory have other ...
Alexander Lawaetz's user avatar
3 votes
1 answer
1k views

Notification system

I would like to implement a mail notification system Notification.cs ...
user avatar
4 votes
2 answers
8k views

Handing "Others" option in dropdown in ASP.Net MVC 5

Business Logic I have a company referral form, and in that form I have dropdown to select from a company list. But when a company is not found in the dropdown, the user can select option as "others", ...
Unbreakable's user avatar
3 votes
1 answer
16k views

Display a dropdown based on another dropdown change

I have a dropdown and when that dropdown changes I want to display/render another dropdown. Can someone help me improve it? So, a person requests for getting referred in a company for a job. When ...
Unbreakable's user avatar
6 votes
2 answers
7k views

"Forgot password" functionality

I want to implement the "forgot password" functionality in Asp.Net MVC 5. Here is the code flow: Take user email ID Let the user enter the token received in his email inbox If the token matches then ...
Unbreakable's user avatar
3 votes
2 answers
159 views

Submitting a form

I am using ASP.NET core entity framework. I am using an input submit button to call a method that has a variable attached to it. I am wondering if there is a way to improve my code. Here is my ...
Aaron's user avatar
  • 935
3 votes
1 answer
65 views

Website to Track Project's Progress

This ASP.NET MVC website is for my professor to track my progress on my Checkers app. This is the first time I have build an ASP.NET website entirely on my own, and I would like a review to make sure ...
user avatar
3 votes
2 answers
168 views

User can add and delete customers

I am using asp.net core entitiy framework. The page displays the customers. The user can add new customers or delete existing ones. I am looking for ways to improve my code. Here is my cshtml page ...
Aaron's user avatar
  • 935
1 vote
1 answer
693 views

Update data in partial view

I have partial view which update data on server. Partial view contains list of configurations (can be check box or text box depends on type). This code is working, and I would like to know how to ...
Raskolnikov's user avatar
-1 votes
1 answer
83 views

Should you declare variables to make Model property names shorter? [closed]

Let's say the model for a razor view has the following name: Model.Receipt and there are a couple of places where you do ...
uioporqwerty's user avatar
1 vote
1 answer
953 views

Bundling JavaScript resources for an MVC app

This is my first MVC app. I'm looking for best practice feedback on how to best bundle the files that I need, the order to bundle them, the placement of the @render ...
Ivan's user avatar
  • 111
10 votes
1 answer
57k views

MVC binding list of values to checkboxlist in an efficient way

I have this code which generates and shows list of selectable items that user can post to controller in order to save into database. Model looks like this: ...
user avatar
4 votes
1 answer
121 views

Joining tables with EF

Here is my database: Here is my viewModel: ...
Oli's user avatar
  • 205
5 votes
2 answers
19k views

A set of Razor HTML helpers for disabling elements

I am developing a huge form with a lot of elements in it. The purpose of this form is editing one domain entity. Now, I finished developing the whole form and it just shows the bunch of text boxes, ...
kseen's user avatar
  • 103
2 votes
0 answers
238 views

Umbraco Macro-Script to grab Contour Form and Node Properties

When it comes to the Umbraco CMS, there are components called "Macro-Scripts" which are essentially a Razor View (.cshtml). They allow you to code a bunch of C# and ...
user3267755's user avatar
4 votes
2 answers
2k views

Displaying separated multi-line text fields

The following code grabs the HTML-encoded, multi-line content of a text field. It then splits the content on line breaks, and finally displays it with commas as separators. I would like to have this ...
user3267755's user avatar
1 vote
1 answer
885 views

Formatting MVC 5 Razor link as a string

MVC 5 doesn't seem to like JavaScript that much. I am creating link in JavaScript to a success method in my Ajax call. Razor: ...
stig's user avatar
  • 113
4 votes
1 answer
11k views

Listing users in Azure Active Directory

The code below is the Index Action from a User Controllers. Basically this code returns a list of users from Azure Active Directory using Azure Authentication Library (ADAL). However I need to show ...
Luis Valencia's user avatar
5 votes
1 answer
528 views

Redirecting a user

When the user clicks the first button ('Back to List' button), I redirect the user to the Employee List page. Can you please review this and suggest if there is any better way of achieving the same? <...
iniki's user avatar
  • 335
6 votes
3 answers
4k views

Monkeying around with Survey Monkey and Asp.Net Mvc

Intro I've been a desktop dev for a long time now, and have never really had to monkey with web development until very recently. I have a need to do some custom integration with Survey Monkey's Api ...
RubberDuck's user avatar
  • 30.8k
1 vote
3 answers
2k views

Partial view for frequently used drop down lists

I have one input that is needed in many forms, so I created a partial view for that. In the partial view I query the database and generate a drop down list. I just want to make sure, this is the best ...
Akbari's user avatar
  • 179
3 votes
1 answer
352 views

Razor view to render simple scaffolding for complex type

After several attempts to follow my intuition that this code can be refactored to something more DRY, I keep hitting road blocks. Hoping someone can see a refactor that might get me going in a nicer ...
Aaron Anodide's user avatar
1 vote
4 answers
10k views

Partial page refresh Ajax call on button click

...
Luke Osborne's user avatar
4 votes
1 answer
107 views

Generate N pairs of checkboxes and N textboxes

I've written a piece of code, where a pair of checkboxes and a textbox are generated N amount of times. Depending on what's in the DB, the checkbox/textbox may have a default value or are left empty. ...
GillesDV's user avatar
  • 155
3 votes
1 answer
51 views

Disabling buttons on forms

I have 5 different forms where I am disabling the submit button when a valid form is submitted so the form can only be submitted once. I am using a hidden field on each form to get the form Id. ...
user3922757's user avatar
4 votes
3 answers
159 views

Make huge view in C# readable and maintanable

I have an application that is using MVC5 with C# and Razor Engine. This view displays a huge table: ...
Flame_Phoenix's user avatar
3 votes
1 answer
1k views

Quiz form website

I'm trying to get a good grasp on ASP.Net MVC, Razor and RadioButtons, so I tried to make a quiz to test my skills. I implemented a working quiz form in the following way in Razor (not posting the ...
David Jiménez Martínez's user avatar
4 votes
2 answers
12k views

Is it "legit" to use a Linq query in a razor view?

I have a Linq query in my razor view like below. Its just getting contacts that belong in the group. ...
smarble's user avatar
  • 143
3 votes
1 answer
171 views

Replacing div if there is any validation error connected with the div value

I have an input group: ...
szpic's user avatar
  • 187
10 votes
2 answers
4k views

Feature-based authorization

Feature-based authorization It seems to me that if you rely on roles to authorize a web application it makes it very difficult to render UI or code based on a set of features. This means that each ...
jwize's user avatar
  • 199
7 votes
3 answers
817 views

Ternary extension method

I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup. Is there a better way to write this ...
TugboatCaptain's user avatar
5 votes
2 answers
3k views

Convert looping statement to linq mode

I have a model object class like this ...
None's user avatar
  • 377
5 votes
1 answer
186 views

Displaying alert from an action

This code works great, but I think it can be reduced. ...
SoundwaveUwU's user avatar
2 votes
1 answer
281 views

Passing a true/false value to a model used in a controller

This passes the value of true/false to model which I can use in my controller. How can this be cleaned up? ...
user2094139's user avatar
18 votes
0 answers
1k views

PowerShell module for formatting objects using Razor

I managed to get something up and running, but I've no idea whether there are better ways to do this. I've spent all morning trying to figure out the best way to use parameters (allowing objects from ...
Danny Tuppeny's user avatar