Reputation: 495
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.
Upvotes: 0
Views: 2136
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
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