Check out the following:
<a href="/test?x=@if (Model.IsTest) { @(1) } else { @(4) }"></a>
Is there a better way to write this instead of the @(1) and @(4)?
Razor syntax is a simple programming syntax for embedding server-based code in a web page. In a web page that uses the Razor syntax, there are two kinds of content: client content and server code.
Just add the id property to the html-attributes. That will override the default id generated by the editorfor-helper-methode. Save this answer.
Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language.
Following are the rules for main Razor Syntax: Razor code blocks are enclosed in @{ … } Inline expressions (variables and functions) start with @ Code statements end with a semicolon.
You can use the conditional operator:
<a href="/test?x=@(Model.IsTest ? 1 : 4)"></a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With