Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Razor C# Html.ActionLink to create empty link

Tags:

asp.net-mvc

How would you use an Html.ActionLink to render the following link -

<a href="javascript:void(0);"></a>

It may seem silly to do this, but sometimes I need a link that has link functionality (rollover pointers, etc.) but does not go anywhere. And I want to use an Html.ActionLink for code consistency.

I have tried different variations of Html.ActionLink but I keep getting messages about things not allowed to be null.

like image 478
A Bogus Avatar asked Feb 12 '13 19:02

A Bogus


People also ask

What is Razor C#?

Razor is a markup syntax for embedding . NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.

Is Razor better than MVC?

From the docs, "Razor Pages can make coding page-focused scenarios easier and more productive than using controllers and views." If your ASP.NET MVC app makes heavy use of views, you may want to consider migrating from actions and views to Razor Pages.

Is ASP Net razor?

Razor syntax is based on a technology from Microsoft called ASP.NET, which in turn is based on the Microsoft . NET Framework. The.NET Framework is a big, comprehensive programming framework from Microsoft for developing virtually any type of computer application.

What is Cshtml vs HTML?

Cshtml is basically razor view extension and any view renders in html finally. You need to use Razor in your application as it supports server side code but raw html does not.


1 Answers

@Html.ActionLink(" ", "", "", new {href="javascript:void(0)"})

will render as

<a href="javascript:void(0)"> </a>
like image 51
Joe Avatar answered Sep 30 '22 14:09

Joe