Click here to Skip to main content
15,891,567 members
Everything / Programming Languages / Razor

Razor

Razor

Great Reads

by Pete O'Hanlon
Rather than littering a razor component with @if (a == b) logic to show items, use render fragments to make a declarative component
by Ken Haggerty
Scaffold and modify Identity in the new ASP.NET Core 2.2 Razor pages template
by Coding Notes
An introduction to ASP.NET Core MVC
by Ajcek84
Implementation of radar chart for various .NET platforms

Latest Articles

by Victor Sirghii
On the parent razor page, we add Partial View which will serve as the updatable container. On Ajax calls from the parent page, we update only Partial view content, not the whole page, thus creating a smooth user interaction experience.
by Jani Giannoudis
Structured approach to ASP.NET Localization
by Pete O'Hanlon
Rather than littering a razor component with @if (a == b) logic to show items, use render fragments to make a declarative component

All Articles

Sort by Updated

Razor 

9 Mar 2018 by #realJSOP
If I recall correctly, I used the technique described at this link to persist data between requests (the site is blocked at work, but the URL seems familiar): Getting information into the Layout without using ViewBag. – jgauffin's coding den[^]
25 Jan 2019 by #realJSOP
Sharing files between multiple web apps in a single solution.
24 Apr 2019 by #realJSOP
You cabn't do razor pages without controllers. The db work is done from the controller - not the view. The view simply presents the data to the user in the form of appropriate markup. Once data has been retrieved from the db, put it into a session var if you don't want to keep making the round...
25 Jun 2019 by #realJSOP
I think you want innerHtml instead of html.
9 Sep 2013 by .Net_d19
I use a ckeditor, which wirte text in database in html tags.How can I read it and show as bold text, for example.some text but I getting only html text.
9 Sep 2013 by .Net_d19
I found the solution.Use @Html.Raw(text)
10 Feb 2015 by /\jmot
public class CheckBoxItem{ public string Code { get; set; } public bool IsChecked { get; set; } public string Label {get;set;}}razor: @Html.HiddenFor(x => x.Code) @Html.CheckBoxFor(x => x.IsChecked)@Html.LabelFor(x => x.IsChecked,...
22 Jun 2014 by 2011999
In MVC3 How to add Register Form in Login Page?
15 May 2013 by _Amy
You need to use javascript ConfirmBox[^] for confirmation before saving and AlertBox[^] to show the notification after saving.---Amit
2 Nov 2014 by _Maxxx_
Let's say your equation is X^2 + Y^2Then you could have two variables (integers, probably) and set them each to a random number. (probably within certain limits - do you want to allow negative numbers, for example)Then get the user's attempt into another variable (answer).Then...
7 Jul 2023 by A Belal
I want to create invoice Error Is An unhandled exception occurred while processing the request. SqlException: Incorrect syntax near '/'. Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action...
15 Sep 2014 by a.anvesh
I have dropdown with values, whenever user selects a value from dropdown on change event it fetch data from table through EF and display in the page i.e. has input textboxes.Thanks in advance
23 Oct 2013 by A.Girish
Hello Friends i'm back with some questions which will help me.Answer as links directly give some information as Answer to my questions1)What is Razor is it having any relation with java script,whats the use of this we already having javascript for scripting techniques,html ,css for...
30 Dec 2013 by Aaditya parcha
Hi,i have a student class like belowpublic class Student { public int stdId { set; get; } public string stdName { get; set; } public string dept { get; set; } }and my controller code is public ActionResult Student() { ...
6 Feb 2014 by Abbas K
Hi,I have created the project template for my MVC projects.And also I have created the wizard for these templates. Now I have used the project templates names are MVC3Razor,MVC4Razor,MVC5Razor, MVC3Aspx,MVC4Aspx, MVC5Aspx. Right now I have used 6 templates for my MVCprojects. Now I...
16 Jul 2013 by abbaspirmoradi
Hi every body.I create a mvc3 app.I use a ckeditor in my App for save news.I have a Content class for model: public class Content { [AllowHtml] public string Text { get; set; } }this is My razor view code:@model...
16 Jul 2013 by abbaspirmoradi
Ok.I find Answer.I use this and my problem is solved.@Html.Raw(Model.Text)But I do not delete this question for guys that have such problem.
22 Jul 2013 by abbaspirmoradi
hi all.Please Help me.I use ckeditor_4.2_full in my mvc3 website.it works when I test it on my pc.(in FireFox and Chrome).But when I upload my website on server, not show anything where it must be exist.why this happens? I ref it in head of page :
23 Jul 2013 by abbaspirmoradi
finally I find solution and my problem Solved.If you have same problem see this
27 Apr 2015 by Abdul Samad KP
remove location path=""Try this
28 Aug 2013 by Abhinav S
Try ViewBag.pid instead of @View.pid.
28 Aug 2013 by Abhinav S
Try ViewBag.pid instead of @View.pid.
30 Mar 2014 by Abhinav S
This error occurs when you access a property of an object that is null.As a basic step, ensure you check for nulls before accessing properties of objects.This however, may suppress the error butmay not help you solve the problem.For this ensure, your connection is correctly...
1 May 2014 by Abhinav S
You would use javascript or JQuery rather than MVC code.For e.g.(function() { $("#chkrmark").first().focus()});
19 Jun 2015 by Abhinav S
You have an option to create a WIX installer - WiX installer for MVC4 project[^].
22 Dec 2012 by Abhishek Pant
Change .cshtml to .aspx. Do not use the Razor engine.and this thead is for you-Allow Design View for MVC3 and Razor View Engine [^]I hope it solves your question.
10 Apr 2014 by Abinash_Sahoo
you can follow this approach[^] to disable the buttons from controller itself after execution of your postback event (within Index Action). Client side script is not required in this scenario.
25 Jul 2022 by Adam Jones
How Can i make the EditorFor input disabledi have tried using the below which doesn't work@Html.EditorFor(model => model.TaskName, new { disabled = "disabled", @readonly = "readonly" })
25 Sep 2013 by Adam Jones
The disable attribute does not return a value read only works OK though
16 Jun 2013 by Adam Tibi
ASP.NET MVC Views give you the power of Razor View Engine with the flexibility of writing C# code. However, if you do too much C#, you will end up with Fat-Razors that need to go on a diet or you might be risking separation of concern attacks.
10 Dec 2012 by adama74
I'm also working on a similar task - mine is to extract test-nodes from html/cshtml/aspx/etc. type files.So far, I am using the HtmlAgilityPack to parse the HTML - but how to distinguish Razor markup from plain-text during parsing - THAT is the question.I haven't tried it out yet, but one...
2 Jul 2012 by ADNANE-Dev
I have this problem: I want to store a list of phone numbers where the first is rended by default with a partial view, the others are created dynamically when I press a link (i.e.: Add Phone number)...In order to do this, I created a template with the fields I use, that is the following:...
9 Jan 2013 by Adrian Holland
JSRazor brings the power of razor-like templates to client-side javascript.
17 Jul 2016 by AFell2
IEnumerable is a generic collection of enumerated values (i.e., a list of objects). The code is casting the dynamic object ViewBag.Albums as a generic collection and then going through each enumeration by using the foreach command.
21 Jun 2015 by afiqdoherty
In my controller code, I need to return two objects to the Details view (details.cshtml)Below is the Controller code:FinishProductCompleteForm FinishProductCompleteFormDetails =...
31 Mar 2015 by Afzaal Ahmad Zeeshan
To do that, you're using the function named filter. You need to handle this event and prevent the form to be submitted (which is the actual intended action to be triggered when user clicks on submit button). To prevent this, you can add event.preventDefault();To prevent the default...
18 Dec 2016 by Afzaal Ahmad Zeeshan
That image is working fine, just use it like, This loads the image, just make sure you have the "http://" before other it will look under your own project website...
4 May 2023 by ahmed_sa
I worked on asp.net mvc razor pages . I face issue I can't pass data from page model to view What I have tried: what i try 1- I create view model as public class AddUserViewModel { public int SelectedBranchId { get; set;...
6 May 2023 by ahmed_sa
I working on MVC razor page with .NET core 7 .I face issue Ajax request not return branches drop down list based on selected value from drop down list country . with another meaning I need cascade branch drop down list based on country drop down...
13 May 2023 by ahmed_sa
I working on razor page with .NET core 7 . my mainly issue How to pass unchecked checkboxes from html page to page model on post method ? so If I have group of checkboxes not checked so I need to pass it to page model as List on post method...
27 May 2023 by ahmed_sa
I work on asp.net razor page Login user name and password . I call Web API validate user name and password . my issue I face it I can't receive data returned after login success JSON data returned from web API after success login username and...
4 Jun 2023 by ahmed_sa
I work on razor page asp.net .I face issue I can't show user details using mouse or popover without using bootstrap modal I pass user details using temp data from model to view and data passed success can you apply popover for sample code...
9 Jun 2023 by ahmed_sa
I work on asp.net razor page model . i face issue i can't edit data table on same page by edit cell without redirect to another page I need to edit cell on same page I need to edit data on table by edit every cell on rows my code details...
18 Jun 2023 by ahmed_sa
I work on razor asp.net page model . i need to implement tree view with children's checkboxes then submit changes on every parent from selected checkboxes so are you have any sample on razor page asp.net can you help me by provide me sample or...
22 Jun 2023 by ahmed_sa
I work on asp.net razor , i get error when try make ajax request to access OnPostshiftDataUp ERROR : Failed to load resource: the server responded with a status of 400 () console.log(formdata) // serialize data ...
24 Jun 2023 by ahmed_sa
I work on razor asp.net core .i face issue selectedbranchid is inside post form form is get selected value without any issue but if i use another post and get selectedbranchid it become null why so How to solve issue please on page model ...
2 Jul 2023 by ahmed_sa
I work on razor asp.net . I face issue I can't get value of blackprintername on bootstrap model although I get the values of this property on page model but on razor html not display on input text box Black server Ip or black printer name . I...
6 Jul 2023 by ahmed_sa
I work on an ASP.NET Core razor page. I need to retain value of address on the page after submit, because I check value of Address after submit - it is not retained, and becomes null. I need to retain the value of the Address without resetting,...
7 Jul 2023 by ahmed_sa
I work on razor asp.net core I need to allow datatable to have paginations options drop down with 5,10,15,20,25 so when load data it must display default rows per page as 10 rows as first page if i need to increase it to 10 or 15 etc it will...
8 Jul 2023 by ahmed_sa
I work on asp.net core entity framework I have csharp function done using ado dotnet stored proceure i need to convert it using entity framwork core with another meaning how to call stored proceure using entity framework core 6 and i don't...
9 Jul 2023 by ahmed_sa
I work on razor asp.net core . I face issue i can't store selected value id and selected text of select option drop down on hidden fields so I need to create two hidden fields first hidden field to store selected value id and second for store...
8 Sep 2013 by aida1986
Hi , I have this method :public static IEnumerable ListeSessionFrais(MpxFraisContext db, int siteID, int stval, string codeFrais) { var sessionfrais = (from D1 in db.H59_MpxSessionFrais where D1.CodeFrais == codeFrais ...
10 Sep 2013 by aida1986
Hi , I have this method :public static IEnumerable ListeSessionFrais(MpxFraisContext db, int siteID, int stval, string codeFrais) { var sessionfrais = (from D1 in db.H59_MpxSessionFrais where D1.CodeFrais == codeFrais ...
11 Sep 2013 by aida1986
i'm working with Nunit not MS test and i want to have test class for this method
11 Sep 2013 by aida1986
how to use mock in test class ?
16 Sep 2013 by aida1986
I want to test a big number of data input and ouput with Nunit but i haven't any idea if someone has an idea tell me pls , khnowig that my project is done with ASP.NET MVC 4, RAZOR , Linq to enties
16 Sep 2013 by aida1986
i use httpContextBase in almost of method that i want to do a test , and the result of almost querries contains more than 300 rows ,i can't do the test with simple Nunit test
24 Aug 2017 by aiswarjya1
How to show all data in a list using EF and MVC What I have tried: i write a code to show a list TeleGUID Screen Name Mobile Number @foreach (var item in Model) { @Html.ActionLink("Edit", "Edit", new { id =...
30 Oct 2012 by Ajay Bachale
You can use ActionLink as
23 Jul 2018 by Ajcek84
Implementation of radar chart for various .NET platforms
19 Jun 2015 by Ajith Ravindran
@(Html.Kendo().Grid() .Name("transactionGrid") .Pageable() //.Editable(editable=>editable.Mode(GridEditMode.InLine)) .Columns(colums => { colums.Bound(p =>...
22 Jun 2015 by Ajith Ravindran
Hey issue is solved by adding culture. :) thank you kendo.culture("en-GB");
24 Mar 2014 by Alem.B
Hi!I have some difficult time to pass data to Partial view httpPost ActionResult method in Controller.Let me explain:1.Have entity which i have been generated with Entity Framework ORM and this looks like this.
22 May 2014 by Alex Taimassov
Learn how to build an interface that allows you to scroll through thumbnails in an album and view each selected image.
23 Jan 2014 by AlexHarmes
I am not able to create an array to input into a db. Its most likely my syntax as this is my first MVC, Razor project, so if you can spot the errors and tell me it would be a huge help!This is my view; // Checkbox ...
1 May 2014 by Amalraj Ramesh
Hihow to focus this check box in mvc@Html.CheckBox("chkrmark", false, new { id = Model.objremarksmasterlist[loop].remarksid })any suggestion??
31 May 2018 by Ameen Shamsan
I'm following a tutorial on how to build a website with MVC. I created the project as Web under C#, then chose Empty from ASP.Net 4.6.1 Templates and chose the option MVC. I created two new folders and added bootstrap, CSS, and fonts files to these new folders. I also created a new folder...
6 Oct 2014 by aminsaadatia
I have 10 records and My first record when I click on the picture of a field of a field picture shown But if a record 10 shots in a field in the same column I click on the image first record will be displayed again. In general I click on any field in the same column of the first record...
6 Oct 2014 by aminsaadatia
These are three images from the list.If you look at my first record the image the image the color purple, but when I click on my picture 3 Picture # 1 will be displayed. I'm so upset :(
7 Oct 2014 by aminsaadatia
My friend. My problem is that I took pictures of the database are read. And I have no information from the pictures I took, and now I want to run them by clicking Show me. The same
3 Sep 2013 by Amir Hamza Md. Kayes
Please on page render populate the list as ViewBag.List= ......@Html.DropDownListFor(model => model.Id, new SelectList(ViewBag.List, "value", "text", Model.SelectedId))
13 Dec 2013 by Amir Hamza Md. Kayes
you can redirect the action or return full view or return PartialView("")
17 Jul 2015 by Amit Karyekar
Problem Description:I a trying to pass the Ienumerable data from controller to view to populate my dropdownlist.While doing so i have somehow succeded to get the data till the controller.How do i pass it to the view?.I am a bit unaware about the razor syntax as m a rookie fr mvc.Any help...
23 Aug 2012 by Amit Patel1985
Hello All,I need to add rich box editor in the Asp.net Razor web site.can any one please provide sample for this.thanks and regards,Amit Patel
29 Jun 2015 by Amit Samnani
hi guys, i had developed on project in asp.net MVC. Now, as per my new requirement i want to integrated new design so, my question is in razor-view which syntax is better to use html or razor view syntax.
1 Nov 2015 by AmruthaNair
Hi, I want to export the content to word file which is in a div in my view page. Once when i tried, the word file got exported with html tags(div). How can i get rid of those html tag and show the exact content.Please provide sample code. Thanks.
10 Feb 2015 by anand vemuri
//use this code this will help you to post the data and get the data is call back function, your action method should return the you databse value.$.ajax({ type: "POST", url: "/contrller/Actionmethod", dataType: "json", data: { value:...
17 Jun 2015 by anand vemuri
try here:https://jqueryui.com/datepicker/[^]
6 Jul 2023 by Andre Oosthuizen
You can pass the value as a query parameter in the form submission. a Step-by-step can be followed at - How to pass parameters to action methods in ASP.NET Core MVC[^] Create a C# function that will hold, request and redirect the address value -...
23 Jun 2013 by Andy_L_J
I have this query:var binstock = db.Bin_Material .GroupBy(m => m.Material.Name) .Select( g => new{Name = g.Key,Total = g.Sum(m => m.Qty)});ViewBag.BinStock = binstock;return.View();When I access the result via the ViewBag in the .cshtml:@foreach (var item in...
24 Jun 2013 by Andy_L_J
Cheers, here is what I did://Helper Classpublic class BinStockModel{ public string Name { get; set; } public double Total { get; set; }}and then in my controller:var binstock = db.Bin_Material .OrderBy(m=>m.Material.Name) .GroupBy(m => m.Material.Name) ...
22 Apr 2019 by Anele Ngqandu
have a page that searches employees by campus. The campuses are populated in a select using razor. I then get all the filtered employees but the page refuses to redraw the DOM with the current number of employees I have an onchange() of the select it calls an ajax that will call the...
20 Apr 2013 by anil_bang0011
Hi , Last 4 month i have learn MVC 4 using razor engine. i am very confuse about HTML5 (i don't know anything about HTML 5)what is the differecne in HTML5 and ASP.NET Razor . and how to use in MVC 4 if anybody have any link regarding this Please share with me Thansk
18 Dec 2016 by anil_bang0011
I have imageURl- [^] How can i show in razorIts showing error imageWhat I have tried:[^]
18 Dec 2013 by Animesh Datta
Hello ,try by this procedureIn the design page i declare two input type submit button with same name but different value.one is for create a student information and another is for update a student information.
24 Oct 2016 by Anjali0904
Solved.It worked without giving an controller reference in urlurl: "SetSelectedHO",Thanks.
21 Jul 2019 by Anjali0904
For OnChange event of a dropdown, I am making a ajax call. In the url path, when I give the Controller/Action path it does not hit the method at all.My code looks like:function FillHO() { //alert('Test'); var stateId = $('#ddlHO').val(); $.ajax({ type: "POST", ...
3 Jun 2014 by Ankesh Dave
This article explains the basic usage of MVC Template System
19 Mar 2015 by Antxon
Hi,I´m creating a MVC5 app using Attribute Routing. After reading many Error Handling stuff, I create a CustomErrorHandlerAttribute, create an Application_Error method into global.asax and modify the web.config customErrors tag.The routes are mapped as attributes aka [Route("Account")].......
3 Mar 2014 by Anubhav689
This will definitely help you :http://stackoverflow.com/questions/6937156/returning-multiple-partial-views-from-single-controller-action[^]
4 Mar 2014 by Anubhav689
Hey Chetan,This Article of mine might solve your problem:http://www.c-sharpcorner.com/UploadFile/cd7c2e/implement-insert-update-and-delete-functionality/[^]
29 Apr 2014 by Anubhav689
Hey buddy,try these articles of...
8 Nov 2013 by Anubhava Dimri
You can create a Action Filter that you need to place with the action.And In this Action Filter (OnActionExecuting and OnActionExecuted) you can write your authentication code.
1 Jul 2021 by Anusha T 2021
Hi, I am very new to ASP NET Core razor pages. I have a requirement to set up Google Tag Manager in ASP NET Core razor pages. Usually in the ASP.Net solution we use Google Analytic's tag.js script in page load. In angular we usually set up in...
16 Jan 2012 by anushripatil
URL Rewriting in ASP.NET 2.0[^]http://pietschsoft.com/post/2005/06/29/ASPNET-20-Rewriting-URL-Paths-just-got-a-whole-lot-easier.aspx[^]
13 Oct 2016 by AnvilRanger
A very quick search would have given you the answer.Disqus Integration in Asp.Net MVC5[^]
28 Feb 2013 by apfelsine1
I need to convert data from my model that is available as an C# array to a Javascript array.I tried JavaScriptserializer and other methods I foundbut nothing worked so far. Maybe I got some kind of syntax error.My site also uses Razor Viewengine. I don'T know if that may cause the...
28 Feb 2013 by apfelsine1
Found it. Seems like Razor was causing thisvar Orte = [@Html.Raw(string.Join(",",Model.HaltestellenListe.Select(x=>"'"+x+"'")))];did the trick :-)