简体   繁体   中英

Render enumeration value using code blocks

I want the value of jsonStr to be

"{submitOfferResult: 0}"

instead though it is

"{submitOfferResult: OFFER_ACCEPTED}"

//javascript
var jsonStr = "{submitOfferResult: <%=SUBMIT_OFFER_RESULT.OFFER_ACCEPTED %>}";

//c#
public enum SUBMIT_OFFER_RESULT
{
    OFFER_ACCEPTED = 0,
    QUALIFYING_OFFER_NOT_MET = 1,
    OFFER_ACCEPTED_NOT_HIGHEST_OFFER = 2,
    OSP_CLOSED = 3,
    AUTO_REJECTED = 4
}

Just cast to int :

var jsonStr = "{submitOfferResult: <%=(int) SUBMIT_OFFER_RESULT.OFFER_ACCEPTED %>}";

Otherwise it's calling ToString() on the enum value, which will use the name where possible.

Note that to follow .NET naming conventions, your enum would be:

public enum SubmitOfferResult
{
    OfferAccepted = 0,
    QualifyingOfferNotMet = 1,
    OfferAcceptedNotHighestOffer = 2,
    OspClosed = 3,
    AutoRejected = 4
}

And then:

var jsonStr = "{submitOfferResult: <%=(int) SubmitOfferResult.OfferAccepted %>}";

您需要将枚举转换为数字类型:

(int)SUBMIT_OFFER_RESULT.OFFER_ACCEPTED

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM