简体   繁体   English

当我尝试通过JS访问ViewData时遇到编译错误

[英]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.

相关问题 当我尝试通过C#访问中运行查询时出现错误 - i get error when i try to run query in access through C# 尝试更新访问数据库中的记录时出现错误 - I am getting an error when I try to update records in my access database 当我尝试从 Unity StandardAssets 脚本访问“EnginePower”时出现错误 - I'm getting an error when I try to access `EnginePower` from Unity StandardAssets script 当我尝试使用DotNetOpenAuth访问其API时,从LinkedIn获得HTTP 400错误 - Getting a HTTP 400 Error from LinkedIn when I try to access its API with DotNetOpenAuth 尝试在Windows 2000上安装程序时出现错误 - Getting error when I to try to install my program on Windows 2000 当我尝试 Output 时出现错误 从下拉列表中选择了什么 - Getting an Error When I Try To Output What Was Chosen From a Dropdown 尝试更新用户时收到无效的电子邮件错误? - Getting invalid email error when I try to update a user? 当我尝试更改 TextBlock 文本时出错 - Getting error when I try to change TextBlock text ViewData编译错误:BC30203:预期的标识符 - ViewData Compilation Error : BC30203: Identifier expected 尝试删除文件时拒绝访问 - Getting access denied when try to delete file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM