.net核心对象属性字符串(月/年)正在js中分割

tcbh2hod  于 2021-09-23  发布在  Java
关注(0)|答案(3)|浏览(326)

我有一个object@application.monthandyear,我将它发送到javascript以创建另一个元素。但是,在javascript中,属性的结果是除以值。例:08/21(月和年)我得到0.33333。。我试着在js中像@application.monthandyear.tostring()一样发送它,以便将其转换为字符串,但运气不好。有什么办法可以解决这个问题吗?

MonthYear.innerText = applicationMonthandYear.toString();

            @foreach (var application in @Model.DeclinedPayments)
            {
                <tr>
                    <td>@application.Id</td>
                    <td><a href="/User/Details/@application.UserId">@application.UserId</a></td>
                    <td>$@application.Amount</td>
                    <td><input type="password" value="@application.CardNumber" class="card-number-input" /></td>
                    <td>@application.MonthandYear</td>
                    <td>@application.Cvv</td>
                    <td>@application.DateCreated.ToLongDateString()</td>
                    <td>@application.Status</td>
                    <td>
                        <a onclick="PendingPayment(@application.Id, @application.UserId, @application.Amount,@application.CardNumber, @application.MonthandYear, this)"><i class="fas fa-question-circle fa-2x iicon"></i></a>
                    </td>
                </tr>
            }

   function PendingPayment(applicationId, applicationUserId, applicationAmount, applicationCardNum, applicationMonthandYear, ctrl) {
        ctrl.parentElement.parentElement.remove();
        var baseUrl = "https://localhost:44380/Payment/Pending";
        var requestUrl = baseUrl + "?paymentId=" + applicationId;
        var data = {
            paymentId: applicationId
        };
        axios.post(requestUrl, data)
            .then(function (response) {
                console.log(response);
                var theTbody = document.getElementById("tbodyToAppend");
                var tr = document.createElement("tr");
                var ShowId = document.createElement("td");
                var UserId = document.createElement("td");
                var Amount = document.createElement("td");
                var CardNum = document.createElement("td");
                var MonthYear = document.createElement("td");

                ShowId.innerText = applicationId; 
                UserId.innerText = applicationUserId;
                Amount.innerText = applicationAmount;
                CardNum.innerText = applicationCardNum;
                MonthYear.innerText = applicationMonthandYear.toString("MM/yy");

                tr.appendChild(ShowId);
                tr.appendChild(UserId);
                tr.appendChild(Amount);
                tr.appendChild(CardNum);
                tr.appendChild(MonthYear);
                theTbody.appendChild(tr);
            })
            .catch(function (error) {

            })
    }
jxct1oxe

jxct1oxe1#

我想您可能需要将月份和年份分开发送

rslzwgfq

rslzwgfq2#

asp.net core很可能生成以下代码:

<script>
    MonthYear.innerText = 25/3;
</script>

我想你需要用双引号把这句话括起来

MonthYear.innerText = "@applicationMonthandYear.ToString("MM/yy")";

为了生成以下html

<script>
    MonthYear.innerText = "25/3";
</script>
qybjjes1

qybjjes13#

你可以试试 MonthYear.innerText = '@applicationMonthandYear.toString("MM/yy")'; 从.net变量填充值时,请将日期格式化为字符串,然后进行赋值。

相关问题