Deep in Development
Deep in Development

Reputation: 495

ViewData Compilation Error : BC30203: Identifier expected

I have code below.

    public ActionResult PatrList(decimal PAT_ID)
    {
        ViewData["PAT_ID"] = PAT_ID;
        return View(); 
    }

<script type="text/javascript">
    $(document).ready(function () {
        var PAT_ID = '<%= ViewData["PAT_ID"].ToString() %>';
        $("body").data("PAT_ID", PAT_ID);
    });
</script>

Unfortunately, I got Compilation Error : BC30203: Identifier expected.

enter image description here

Upvotes: 0

Views: 2136

Answers (2)

Deep in Development
Deep in Development

Reputation: 495

Add below line to top of the view page, then it works perfect.

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

Upvotes: 1

Ala
Ala

Reputation: 1503

Try the following:

<script type="text/javascript">
    $(document).ready(function () {
        var PAT_ID = '<%= (ViewData["PAT_ID"]).ToString() %>';
        $("body").data("PAT_ID", PAT_ID);
    });
</script>

or better in Razor engine:

<script type="text/javascript">
    $(document).ready(function () {
        var PAT_ID = '@(ViewData["PAT_ID"]).ToString()';
        $("body").data("PAT_ID", PAT_ID);
    });
</script>

Upvotes: 1

Related Questions