Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert enum to int inside HTML

Tags:

razor

I have the following line

<div class="row" data-hns-target="salesChannel" data-hns-condition="^@Model.SeenSalesChannel$">

Model.SeenSalesChannel is an enumeration. I would like to convert this to the corresponding int value but

<div class="row" data-hns-target="salesChannel" data-hns-condition="^@(int)Model.SeenSalesChannel$">

is not valid. What else could I do?

like image 528
Sachin Kainth Avatar asked Mar 21 '13 14:03

Sachin Kainth


People also ask

How to convert int to enum in C #?

Here you will learn how to convert Int to Enum in C#. You can explicitly type cast an int to a particular enum type, as shown below. Use the Enum.ToObject () method to convert integers to enum members, as shown below. How to loop through an enum in C#?

How do I cast an enum to a specific type?

And enums can have different underlying types, such as int, short, long, byte. If you know the actual enum type, you can cast it to that specific type directly. If you don't know the actual enum type, or you deal with a generic type, you can use GetTypeCode () method to check the enum type while converting.

What is the use of enum in Java?

As you see enum object is used to store two types of values - one type stores index and enum strings, other type stores reverse of data like string and enum. By default, each enum constants is assigned with numbers starting from 0,1 ie.

How to convert enum myenum to decimals?

enum MyEnum { First = 1, Second = 2, Third = 3 }; string enumStr = MyEnum.First.ToString (); enum MyEnum { First = 1, Second = 2, Third = 3 }; var myEnum = MyEnum.Second; string enumStr = Convert.ToDecimal (myEnum).ToString ("0");


1 Answers

Wrap the whole thing in ()

<div class="row" data-hns-target="salesChannel" data-hns-condition="^@((int)Model.SeenSalesChannel)$">
like image 64
Mark Coleman Avatar answered Oct 08 '22 02:10

Mark Coleman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!