0

我希望 jsonStr 的值为

"{submitOfferResult: 0}"

相反,虽然它是

"{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
}
4

2 回答 2

4

只需投射到int

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

否则它会调用ToString()枚举值,它将尽可能使用名称。

请注意,要遵循 .NET 命名约定,您的枚举将是:

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

进而:

var jsonStr = "{submitOfferResult: <%=(int) SubmitOfferResult.OfferAccepted %>}";
于 2013-05-09T18:57:20.037 回答
2

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

(int)SUBMIT_OFFER_RESULT.OFFER_ACCEPTED
于 2013-05-09T18:57:13.913 回答