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.
答案 0 :(得分:1)
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>
答案 1 :(得分:1)
将以下行添加到视图页面的顶部,然后它可以完美运行。
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>