开发者

Getting a compilation error when I try and access ViewData through JS

开发者 https://www.devze.com 2023-02-10 23:59 出处:网络
ViewData[\"results\"] = indication.Model.prepaymentList; return View(@\"~\\Views\\Indications\\TermSheetViews\\Swap\\PrePayment.asp开发者_C百科x\", indication.Model);
ViewData["results"] = indication.Model.prepaymentList;
return View(@"~\Views\Indications\TermSheetViews\Swap\PrePayment.asp开发者_C百科x", indication.Model);

This works fine but my compilation error is happening on the view on this line:

var prepaymentList = <%= ViewData["results"]; %>;

What's wrong?


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. I would recommend you using a strongly typed view and model so that finally you have:

var prepaymentList = <%= new JavaScriptSerializer().Serialize(Model) %>;


A quick guess: try removing ; after ]

0

精彩评论

暂无评论...
验证码 换一张
取 消