Skip to content

ErcanOPAK.com

  • ASP.Net WebForms
  • ASP.Net MVC
  • C#
  • SQL
  • MySQL
  • PHP
  • Devexpress
  • Reportviewer
  • About

Tag: Razor

ASP.Net MVC

How to use if else block to decide style in Razor

- 20.06.23 - ErcanOPAK comment on How to use if else block to decide style in Razor

Declare a local variable at the beginning of the View: @{ var yourStyle = “”; if(Model.Condition) { yourStyle = “float:left;”; //specific conditions and logic } else { yourStyle = “float:right;”; //any other conditions and logic } } and then just use it in your div: <div style=”@yourStyle”>

Read More
ASP.Net MVC

How to make a checkbox or dropdown readonly in Razor

- 15.09.22 - ErcanOPAK comment on How to make a checkbox or dropdown readonly in Razor

You can add @disabled = “disabled” to the last parameter named HtmlAttributes. @Html.CheckBox(“someNameForYourCheckBox”, CheckedValue (True or Not), new { @disabled = “disabled” }) @Html.DropDownList(“someNameForYourDropDown”, YourSelectList (comes from Model), new { @disabled = “disabled” })  

Read More
ASP.Net MVC / Razor

How to put text inside MVC Razor code block

- 20.05.22 - ErcanOPAK comment on How to put text inside MVC Razor code block

The contents of a code block ({ … }) are expected to be code or markup (tags), not plain text. If you want to put text directly in a code block, you have three choices: Wrap it in any HTML tag Wrap it in the special Razor <text> tag, which will just render the text without the […]

Read More
ASP.Net MVC / ASP.Net WebForms / Razor

How to insert space in Razor Asp.Net

- 09.01.22 - ErcanOPAK comment on How to insert space in Razor Asp.Net

@if (condition) { <text>&nbsp;</text> @:&nbsp; }  

Read More
ASP.Net MVC

How to use ? : if statements with Asp.Net Razor

- 30.10.21 - ErcanOPAK comment on How to use ? : if statements with Asp.Net Razor

<span class=”btn btn-@(item.Value == 1 ? “primary” : item.Value == 2 ? “warning” : “danger”)”>EVALUATE</span> Briefly, we can say that @(condition ? “the value, if the condition is true” : “the value, if the condition is false” )

Read More
ASP.Net MVC

Getting index value in Razor ForEach

- 24.10.21 - ErcanOPAK comment on Getting index value in Razor ForEach

@{int i = 0;} @foreach(var myItem in Model.Members) { <span>@i</span> @{i++;} }  

Read More
ASP.Net MVC / JavaScript

Populating Javascript array with Model in ASP.Net MVC Razor

- 23.10.21 - ErcanOPAK comment on Populating Javascript array with Model in ASP.Net MVC Razor

We just need to loop through the razor collection to populate the Javascript array as below: @foreach (var item in Model) { @:$(function () { @:$(“#map”).googleMap(); @:$(“#map”).addMarker({ @:coords:[@item.Latitude], @:title: `@item.City, @item.District`, @:text: `@item.Address` @:}); @:}); }  

Read More
ASP.Net MVC / C# / JavaScript

Pass model from Razor view to JavaScript

- 23.10.21 - ErcanOPAK comment on Pass model from Razor view to JavaScript

Let’s say you send a model called “MyModel” from controller to view. In Controller: … var result = new MyModel() { Id = 1, Name = “Ercan”, FavoriteTeam = “Galatasaray”, FavoriteGame = “Half Life Series” } return View(result); … and now we will send this model which comes with result to Javascript via setName function: […]

Read More
ASP.Net MVC / C# / Razor

@helpers in Asp.NET MVC Razor

- 19.11.19 | 27.11.19 - ErcanOPAK comment on @helpers in Asp.NET MVC Razor

A @helper in Razor ultimately defines a function you can invoke from anywhere inside the view. The function can output literal text and can contain code blocks and code expressions. Don’t forget that heavy amounts of code in a view can lead to grief. You have @PluralPick(Model.Count, “child”, “children”). @helper PluralPick(int amount, string singular, string […]

Read More
ASP.Net MVC / C# / Razor

Using Code Blocks, Mixing Text & C# Code and Comments in Asp.NET MVC Razor

- 06.08.19 | 22.11.19 - ErcanOPAK comment on Using Code Blocks, Mixing Text & C# Code and Comments in Asp.NET MVC Razor

In Razor you can create blocks of code nearly anywhere using @{ }. A block of code doesn’t emit anything into the output, but you can use the block to manipulate a model, declare variables, and set local properties on a view. Be extremely careful about having too much code in a view, however, because […]

Read More
December 2023
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031
« Nov    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (704)
  • Get the First and Last Word from a String or Sentence in SQL (698)
  • How to select distinct rows in a datatable in C# (560)
  • Add Constraint to SQL Table to ensure email contains @ (455)
  • Average of all values in a column that are not zero in SQL (373)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (344)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (338)
  • Find numbers with more than two decimal places in SQL (325)
  • Confirm before process with ASPxButton in Devexpress (316)
  • ASPxGridView – Disable CheckBox based on condition in GridViewCommandColumn (292)

Recent Posts

  • How to find a specific text string in a SQL Server Stored Procedure, Function, View or Trigger
  • How to convert JPG or PNG to WebP in batch or single mode
  • How to get the first and the last day of previous month in SQL Server
  • Not Null check on LEFT function with T-SQL
  • NICE 100 YILLARA TÜRKİYEM
  • How to delete all commit history in github
  • How to display HTML components on the same line in CSS
  • How to insert results of a stored procedure into a temporary table
  • How to remove all non alphanumeric characters from a string in C#
  • How to get the Xth Day of the Week of the Year in C#

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (704)
  • Get the First and Last Word from a String or Sentence in SQL (698)
  • How to select distinct rows in a datatable in C# (560)
  • Add Constraint to SQL Table to ensure email contains @ (455)
  • Average of all values in a column that are not zero in SQL (373)

Recent Posts

  • How to find a specific text string in a SQL Server Stored Procedure, Function, View or Trigger
  • How to convert JPG or PNG to WebP in batch or single mode
  • How to get the first and the last day of previous month in SQL Server
  • Not Null check on LEFT function with T-SQL
  • NICE 100 YILLARA TÜRKİYEM

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter

© 2023 ErcanOPAK.com

Proudly powered by WordPress | Theme: Xblog Plus by wpthemespace.com