我希望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
}
答案 0 :(得分: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 %>}";
答案 1 :(得分:2)
您需要将枚举转换为数字类型:
(int)SUBMIT_OFFER_RESULT.OFFER_ACCEPTED