gene
gene

Reputation: 2108

How to get the data from the Model into a JavaScript function?

I have a Model that contains Date of the report.

On a click, I want to display the report for that date in the popup.

I have the following logic:

 Click to view Report <button type='button' class='k-button btn-icon-sm btn-hyperlink' id='btnViewRpt' onclick='ViewRptData()'><span class='k-icon k-i-hyperlink-open-sm'></span></button>

Then I have a script that calls a function:

<script>

    function ViewRptData()
    {
        var test = {@Model.FileDate}
        alert(test);
    }

</script>

When clicking on the button, I'm getting a console error:

SCRIPT1003: Expected ':'

What am I doing wrong?

Upvotes: 0

Views: 43

Answers (1)

sanfalero
sanfalero

Reputation: 382

You need to set your model property into a property of the javascript object.

 var test = { fileDate: '@Model.FileDate'};

Upvotes: 1

Related Questions