[英]Getting a compilation error when I try and access ViewData through JS
ViewData["results"] = indication.Model.prepaymentList;
return View(@"~\Views\Indications\TermSheetViews\Swap\PrePayment.aspx", indication.Model);
This works fine but my compilation error is happening on the view on this line: 这可以正常工作,但是我的编译错误发生在此行的视图上:
var prepaymentList = <%= ViewData["results"]; %>;
What's wrong? 怎么了?
A quick guess: try removing ;
快速猜测:尝试删除
;
after ]
之后
]
You have too many ;
你有很多
;
. 。 It should be:
它应该是:
var prepaymentList = <%= ViewData["results"] %>;
Of course writing something like this makes absolutely no sense whatsoever. 当然,写这样的东西绝对没有任何意义。
You probably need: 您可能需要:
var prepaymentList = <%= new JavaScriptSerializer().Serialize(ViewData["results"]) %>;
Which of course leads to another problem which is the usage of ViewData
. 当然哪个会导致另一个问题,那就是
ViewData
的用法。 I would recommend you using a strongly typed view and model so that finally you have: 我会用一个强类型的视图和模型,这样最后你有建议你:
var prepaymentList = <%= new JavaScriptSerializer().Serialize(Model) %>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.