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.
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>
将以下行添加到视图页面的顶部,即可正常使用。
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
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.