Getting a compilation error when I try and access ViewData through JS
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 ]
精彩评论