简体   繁体   中英

Try pass parameter from view to controller method

I have a controller method that returns image from MongoDB, and I want to show it in my view:

<HttpPost()>
        Function ShowImage(cardNumber As String) As FileContentResult

            Dim Handler = New MongoDBHandler()
            Dim newString = cardNumber.Replace(vbLf, "").Trim().Replace("""", String.Empty)
            Dim byteArray = Handler.ReadImage(newString)

            Return File(byteArray, "image/png")
        End Function

I have the javascript function:

function postCardNumber(elm) {
    var CardNumber = $(elm).closest("tr").find(".card-number").html(); 
    var $img = $('<img>');
    $img.attr('src', "data:image;base64," + @Html.Action("ShowImage", "CreditCard", CardNumber));
    $("#myModal").append($img);
}

But there is a red underline under "CardNumber" parameter for the attr function. Why?

Are you sure that razor templates works with JavaScript? You can translate your razor syntax to js/HTML. But I'm not sure that its works vice-versa. Razor syntax transpiled when your page rendered by the server,js starts working when page loaded. You should rewrite your code to js without using razor in this way

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