Click here to Skip to main content
15,891,473 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 Title

Razor 

16 Mar 2014 by Member 10506553
I have an error in my partial view : Object reference not set to an instance of an object which I tried to bybpass by adding this line but it seems not working because I got the previous mentionned error.If I put a break point on the added line (@if (Model.CartItems != null)), the first...
16 Mar 2014 by Sergey Alexandrovich Kryukov
If, as you say it yourself, Model is null in some cases, you should also check if (Model != null) … what you do in this situation really depends on what you want to achieve. You cannot ask more and more questions like that each time similar situations take place; they are way too typical....
16 Mar 2014 by coder771
Try out something like this @{ var cartCnt = 0; if (Session != null && Session["CartCount"] != null) { cartCnt =...
8 Jul 2013 by Liviu Ignat
MVC 3 plugin architecture with embedded razor views: steb-by-step description and demo application.
27 Sep 2023 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.
22 Oct 2020 by listojay
Im having trouble disabling or set textbox to readonly after postback submission.what code do i need from controller to disable a razor textbox in views.please dont suggest to use jquery for me to familiarize mvc thanks.What I have tried:i can do this by default but cant control the...
23 Oct 2016 by F-ES Sitecore
MVC is a server-side technology, you can't use it to dynamically amend the DOM in the browser, so I'm afraid you're going to have to use javascript or jQuery to do this.
22 Oct 2020 by Member 14972759
Solution by ROCH DEVELOPER @Html.EditorFor(model => model.Consecutive, new { htmlAttributes = new { @class = "form-control", @Value = ViewBag.Consecutivo, disabled = "disabled" } })
23 Oct 2015 by Asmaa Rashad
Hello ,iam working using MVC and Entity framework , I have a view that displsy data of "BloodDonors" table from database and i can filter them by their blood group value that selected by dropdownlist ,so i want after choosing specific blood group i call the controller function that filters and...
29 Apr 2019 by TheBigBearNow
I have 2 buttons but I cant bring my model to the page and click a button to determine how to set my model. I’m thinking if I can get my model in my page I’ll be able to figure out these buttons possibly. I tried bring the model like usual new { model = Model} but my model Is still null… Here...
28 Aug 2018 by Member 13944054
in a Razor view... @Html.ActionLink("Cancel", "Index", "Client") @**@ @using (Html.BeginForm("SaveNewClient", "Client", FormMethod.Get)) { . . . Index is action...
28 Aug 2018 by Member 13944054
I don't know if this constitutes a solution but it may help others. I traced the problem to a div.wrapper css section, obtained from a side-navbar solution I found on the Interwebs... div.wrapper { margin: 140px auto; border-radius: 5px; width: 200px; height: auto; float:...
28 Aug 2018 by Member 10371658
make sure that div should not overlap the anchor tag. and make sure you have added Index method in ClientController as Get method. add this, just after the body tag. and try again @Html.ActionLink("Cancel", "Index", "Client")
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.
31 Mar 2014 by Guruprasad.K.Basavaraju
In your view change the IEnumerable to List, that solved a similar issue I had.@model ListIEnumerables are readonly.
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.
25 Mar 2023 by Shaun C Curtis
How to build a Modal Dialog for Blazor
17 Aug 2016 by RAJU-11052090
i trying this but in output its simply displaying text not as dropdownWhat I have tried:var table = document.getElementById("tablett"); var ddlfront = ''; var ddlback = ''; //var...
28 Nov 2011 by Eduard Keilholz
Hey there,I'm trying to create a form using ASP.NET MVC (3). The view uses the Razor engine. I'm trying to add a data attribute to the Form tag :@using (Html.BeginForm("passwordchange", "account", FormMethod.Post, new { @class = "async", data-success =...
29 Nov 2011 by Eduard Keilholz
Oh wow,I just found the answer somewhere online. You need to replace the 'minus' with an underscore.@using (Html.BeginForm("passwordchange", "account", FormMethod.Post, new { @class = "async", data_success = "account.passwordChangeSuccessfull();" }))This will do the trick!
21 Sep 2015 by vini vasundharan
I want to add a '+' symbol below the table that shows the content of a particular table enabling the user to add another row of data to the table. I want the data to be saved in the database.I tried integrating my two current views together but it doesn't work. Here is my View for...
17 Sep 2015 by Krunal Rohit
1st apporach:The View you have shared here is showing all the records from database. If you want to add one more row which means that you are creating a new record. For that you'd be requiring a different View. (Which you removed already)2nd approach:You can do it via jQuery. See this:...
21 Oct 2016 by cigwork
Use dev tools (F12 in Chrome) to inspect the JavaScript that the client has. You might find the URL supplied for the call is not what you expect it to be.Does this...url: '@Url.Action("SetSelectedHO","../../Controllers/ReportsController")'... generate a valid URL? It looks as...
21 Oct 2016 by Vincent Maverick Durano
You don't need to specify the path when using Url.Action() method. You need to specify the Controller name instead.So if you have a Controller that was named ReportsController, then you could try doing something like this:url: '@(Url.Action("SetSelectedHO","Reports"))'Note that...
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", ...
18 Oct 2018 by Member 14024864
This worked for me: url:'../Controller/action'
31 Oct 2019 by Member 14641047
Thanks for solution 4 its work forme , on laravel on ubuntu
3 Feb 2014 by zeeShan anSari
Hi All,Can I use PageMethods in the simple .cshtml page? My application is not MVC but razor works good but when I tried to use PageMethods.xyz(calls,callf); then an error showing PageMethods is not defined. Or there is another method for get the data from other web...
3 Feb 2014 by zeeShan anSari
Thank you......it's work $.ajax({
30 Apr 2019 by Member 14164795
My goal is to dynamically update two fields every time there's a change made to a dropdown list. In my example, the dropdown is a list of employees, and I need the group/subgroup fields to update every time it changes. Using this article and others, I'm attempting to call the C# method I've...
30 Apr 2019 by MadMyche
The difference between the samples is all in what you are returning. The last line in your controller action is return Page();, which will return a plain Page Result with no data being passed into it. The last line of the samples are all return new JsonResult(lstString); which will return a...
30 Apr 2019 by Member 12274397
OnPostSearchCurrGroup() method needs to return Json object,hence it should be of type JsonResult instead actionresult and should return new JsonResult(lstString) instead return Page().
1 May 2019 by Member 14164795
(After making changes based on this question I made yesterday) My goal is to dynamically update two fields every time there's a change made to a dropdown list. In my example, the dropdown is a list of employees, and I need the group/subgroup fields to update every time it changes. I'm...
1 May 2019 by Christian Graus
Do you know how to use Chrome debugging tools? You should use them to watch this code, see what the request returns and see what happens when it succeeds. Your code looks to me like it defines two functions in your success method, it doesn't actually call anything? What is OnSuccessed? As...
9 Mar 2022 by Coding Notes
An introduction to ASP.NET Core MVC
3 Jun 2015 by Karmesh_Madhavi
How i apply width to razor control @Html.RadioButtonFor in mvc4?UserModel.cspublic string Emp_Gender{get; set;}index.cshtml@model MvcApplication.Model.UserModel@using...
3 Jun 2015 by King Fisher
@using (Html.BeingForm()){@Html.RadioButtonFor(m=>m.Emp_Gender,"Male",new { @class = "cssclass" })Male@Html.RadioButtonFor(m=>m.Emp_Gender,"Female",new { @class = "cssclass" })Female}
19 May 2015 by Member 11463029
I have a model object called wage with the following propertiespublic class wage{ public string id {get;set;} public string name {get;set;} public IWageType type {get; private set;} public void SetType(int id) { if(type.Id!=id} { if (id==1) ...
13 Nov 2019 by Richard Deeming
Quote: @using (Html.BeginForm("Bank", "Employee", FormMethod.Post, new { @class = "form-horizontal" })) { ... ... ... } Nested forms are not supported in HTML. Try removing that extra tag, or changing it to a
13 Nov 2019 by Tshumore
I have a Razor MVC 5 form pushing data to a sql database. When i hit submit the form just reloads and the form values are retained. Checking in the database i see that no values are committed. I have the POST version of the ActionResult already decorated with [HttpPost]. Additionally in the...
26 Jun 2012 by Yashebay
hiI am working on asp.net mvc3 based product.and don't wanna use entity framework in my product for database accessI have to use basic database connectivity approach.can anyone give me solution of this problem.how to use it .With Warm Regards,Gaurav ebay
26 Jun 2012 by Tim Corey
In that case, use straight ADO.NET code. Here is some sample code that we sometimes use to read and write data in a SQL database:public static System.Data.DataTable ReadData(string connectionString, string sqlQuery, Dictionary parameters = null){ DataTable myTable = new...
26 Jan 2022 by Sni.DelWoods
My edit view uses partial views to edit different addresses. On submit, the form keys are identical for street and are not assigned to the model. I get: Street[0]: Silicon Road Street[1]: Main Avenue I need something like: customer.Street:...
25 Jan 2022 by M Imran Ansari
You can modify your code in respectively like: EditForm.cshtml @await Html.PartialAsync("AddressEditPartial.cshtml", @Model.Order) AdressEditPartial.cshtml @Model Order
25 Jan 2022 by Richard Deeming
Use the tag helper instead of the PartialFor extension method: @Model EditForm ...
23 Nov 2015 by TheBigBearNow
Hello all,I am currently working with a ASP.Net and JavaScript window.Now I currently have a javascript script run creating a popup window that has multiple controls. Dropdown lists, buttons, etc.I am trying to have it so when you select a certain option in the dropdown list that it will...
30 Oct 2018 by Leonard E. James
Create initial object model and database and display first Razor Page
12 Apr 2013 by devdev13
I'm returning a json data, and I can confirm that it is bringing data back to client. but instead of updating my jqueryaccordion, it asks me to save or open the file. Below is my script and controller. I have used jquery modal dialog to edit the employee details through a partial view, and...
12 Apr 2013 by Moykn
Probably you have forgotten to add jquery.unobtrusive-ajax.min.js to your page, check it please.
24 Apr 2013 by Christoph Keller
Hi,This normally occures if you try to post a form in an IFrame and the result is JSON (mostly used in Ajax-fileuploads.The problem is (in the above mentioned scenario) that IE does not detect the JSON result as a text to display, so it assumes that you want to download it.To...
25 Nov 2012 by jgauffin
How to create a flexible plugin system with Griffin.MvcContrib.
18 Sep 2022 by towaso
A short example on how to create a hierarchical web checklist
25 Mar 2021 by chan200uk
Hi everyone, I am trying to save image path in the database and in the root folder. but it always pass the null value. please see my code below... I will really appreciate any help... thanks in advance What I have tried: ...
25 Mar 2021 by chan200uk
I got that working, there was typo issue...
14 Dec 2018 by tnacer
Hello,I am new to asp.net mvc razor.I have a search form with multiple serach creteria (text box and dropdownlist).My bug is that when i filter for exemple my table that initialy contains 100 rows, it gives me 50 rows. But when i click on second page (number 2 in the paging) i loose...
24 Aug 2015 by ntuthuko-m
Hi,It looks like you forgot to pass the other filters to the razor view in the paging section. The only search filter you have in the paging link is:ViewBag.CurrentFilterYou need to include the selected values from the drop-down in the ViewBag collection and pass them to the view the same...
28 May 2014 by FoxRoot
Hello everyone,today is my off day, so I wanted to spend some time on jquery ui. First I used the ready functions. Now I am trying this in a project that I'm already developing.Simply, there is a textbox that is used to search.My DDataControllerDDataBLL _data = new DDataBLL();...
19 Apr 2012 by Jovan Popovic(MSFT)
Simple tutorial to create first MVC app
28 Sep 2013 by FoxRoot
Hello everyone,I started a project to leran mvc structure. I want to add a login panel first. Whatever, the problem is; I wamt to use Bootstrap.I searched and used Package MAnager Console.First I created an empty ASP.NET MVC 4 projectSecond I used Package Manager Console and typed;...
28 Sep 2013 by Sampath Lokuge
I have completed same steps which you have mentioned.But no run time errors.It's working.So try again with new project on new place.Good luck.Quote:First I created an empty ASP.NET MVC 4 projectSecond I used Package Manager Console and typed;install-package twitter.bootstrap.mvc4...
28 Aug 2013 by sarath from cst
I successfully stored one value in view bag in controller.like below@viewbag.pid=20i want to display this 20 in my view for that i write below code@view.pidBut my problem is i am not able to display in my page please help me out.
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.
28 Aug 2013 by Jitendra Sabat
In your controller writeViewBag.Message = "Welcome to ASP.NET MVC!";To access it in respective view use razor syntax as below@ViewBag.MessageHope this will help you.
29 Aug 2013 by SPASWIN
Try This.. @ViewBag.pid
29 Sep 2016 by ERP.SYSTRONICS@GMAIL.COM
Hi, I am new developer in MVC. I want to create Master Detail Entry With All operation Like Insert,Edit,Delete and View at Master (Parent) and Detail(Child) Level. For Example : Sales InvoiceDataBase Table:SalesInvMain (Id,VouNo,VouDate,CustName)SalesInvItem (...
29 Sep 2016 by David_Wimbley
Since you are new to MVC, the best piece of advice anyone can give you is learn how to research you issues rather than asking strangers on the internet to do the work for you and provide the solution. Master Detail functionality is not trail blazing, it has been done numerous times and has...
15 Sep 2013 by ice_ok
Please help me with problem that changed my life to dark side for last weel Cry | :((I have done the asp.net razor application with Visual Studio 2012 Express for Web, also i have Windows Server r2 with iis to implement my site-application in inner corporation network.My problems are: ...
13 Feb 2015 by Member 11004573
Hello Everyone,i am Trying to Make TEXT Box Who Search data From The Database on Website.i am still Face One Error.Error: "Compiler Error Message: CS1061: 'string' does not contain a definition for 'Title' and no extension method 'Title' accepting a first argument of type 'string' could be...
13 Feb 2015 by Richard Deeming
You've declared the variable Post as a string:var Post="";Remove that line, and use:var Post = Db.QuerySingle("Select * From BlogPosts Where Id=@0 And DatePublished
28 Jun 2015 by kkordinia
I have a question about asp.net 5. Is asp.net web pages are supported in asp.net 5 or deleted ? ( Like asp.net webform)
28 Jun 2015 by praveenlob7
Go through the below link for the details.https://msdn.microsoft.com/en-us/magazine/dn879354.aspx[^]
30 Apr 2019 by simple world
I fixed my problem when i created a new .cshtml file and followed this pages tutorial here With this now it logins my registered users.
5 Sep 2018 by Member 13974128
I've integrated authO in mvc .net core 2.1 and using razor pages,unable to understand how to use authorization if i want to control razor pages access,so sign in and sign out is happening properly but id the user is not authenticated in and to keep the user on the same page , but right now when...
9 Sep 2013 by Jameel VM
I have created an sample which works fine.Please try like that public class TestController : Controller { // // GET: /Test/ public ActionResult Index() { ViewBag.StatusList = ...
9 Sep 2013 by Rakesh Meel
Visit Here...http://forums.asp.net/t/1759232.aspx[^]orhttp://stackoverflow.com/questions/5188563/asp-net-mvc-drop-down-list-selection-partial-views-and-model-binding[^]
9 Sep 2013 by Vishal Pand3y
i am trying to bind a dropdown using partial view my code is For partial View @model TenderKhabarCRM.Models.Status{ @Html.DropDownList("status") }in view Status ...
22 Apr 2013 by Sid Ravalia
How to bind dropdownlist from database in C# MVC razor code?Thank You.
22 Apr 2013 by vaibhav10Dec1987
Syntax:@Html.DropDownList(, IEnumerable Selectlist, html Attribute) Ex:-@Html.DropDownList("lstGroupName", ViewBag.GroupName as MultiSelectList, new { @class = "groupDropdownlist" }) In these I am bind a list into that views controller & assign it to to the viewbag "GroupName". ...
24 Apr 2013 by CringTee
in view @Html.DropDownList("dropDownName",(SelectList)ViewBag.Category, "--Select category--", new { @class = "ClassName" })in controller ViewBag.Category= new SelectList(dbEntities.Categories, "id", "category");// select statement in efhope this help. please vote if...
25 Feb 2014 by ravikhoda
HI all ,i want to bind a List with grid mvc. when i bind model with Grid.mvc it will generate error that can not convert from anonymous list to Model list. on my view i have include the model for login only but my query have inner join and return role type as well which do not find in...
20 Nov 2013 by sarath nath
i am now having my view code like below.@if (!Model.DisableBuyButton || !Model.DisableWishlistButton){ @Html.LabelFor(model => model.EnteredQuantity, new { @class = "input-small" }, " :") @if (Model.AllowedQuantities.Count > 0) { ...
2 Jun 2015 by Member 11737754
Hi Everyone, I need to know, if there is any bootstrap editor/designer which has support for cshtml/razor pages. I am using Asp.Net Mvc , the html pages also contains the razor syntax, I have already tried some Bootstap editors, in which I can upload html pages, make changes to the...
17 Aug 2016 by GREG_DORIANcod
good dayI have the following code ... Pagos Mensuales ...
17 Aug 2016 by GREG_DORIANcod
it was simply just change on my css file the display attributeinput[type="radio"] { display: none; --> change for inline or block o inline-block}
17 Aug 2016 by GREG_DORIANcod
it was simply just change on my css file the display attributeinput[type="radio"] { display: none; --> change for inline or block o inline-block}and for load the event i Use this recomendation in this page Load ASP.NET MVC Partial Views Dynamically Using jQuery | BinaryIntellect...
10 Jun 2012 by Utrech576
&Hey everybodyThis is my CSS-code for a button.I use by the way Razor Engine in ASP.NET/C#.It work in Safari and other web browsers except as IE-9I read everywhere that IE-9 support ‘border-radius’. But it doesn’t work for me!!!input[type="submit"] { border: 0px; margin: 5px...
10 Jun 2012 by Zoltán Zörgő
I have googled for it, and it turned out, that border-radius wont work with (some) input elements in IE9. It is a bug in the CSS3 engine or the problem lies in the fact, that these elements in IE are rather API level controls. Other browser developers have rewritten them from the scratch. I have...
31 Jul 2018 by ParsleySage
EF Core 2.1 (using Razor Pages) I have a table, model and Razor Crud Pages to create new Examination schedules. The db table and model has a foreign key ID to an Examination Dates table and model, which in turn contains key dates that require adding/updating to an Exam schedule at various...
31 Jul 2018 by Mike V Baker
1) This isn't going to be specific to your situation because you're not posting any code so I can't see into your data model. But if you're using EF then you don't have to worry about the primary key foreign key values because that's entity framework's job. Your DBContext will have a data...
17 Nov 2015 by TheBigBearNow
Hello all,I am working on a MVC project, I currently finished three different excel sheets and depending on the type of insurance the user selects a certain default excel sheet format should be used for that insurance.Currently I can only select one format in the return statement. What I...
20 Sep 2021 by KarNullKa
I'd like to find where they're stored files (or paths) like javascripts, css, images. By write I mean for example If there is a collection in the root cshtml...
20 Sep 2021 by Richard Deeming
Simple: the file is called table.css, and it's in the css folder in the root of your site. Since you haven't explained what you mean by "collections" and "this object", we can't tell you anything else.
13 Nov 2015 by TheBigBearNow
Hello all,I am creating an excel sheet that will have multiple rows to display data. The header that I have created populates fine without any issues. Under the header I am creating a table. The table will have titles and a field that will be populated from the database to the right. For...
17 May 2016 by Member 11858460
I am new to MVC and learning.I have one page only where I have a partial view containing a webgrid. If I sort it works, and I can filter using a drop down list. HOWEVER, if I filter, THEN sort, the partial view is the only thing that appears on screen without the parent Index, no CSS,...