So I am returning a view with a List as a model as such:
List<Indications.Analysis.PrepaymentResult> resultsList = Indications.Analysis.PrepaymentResult.GetPrepaymentResult(indication.Mo开发者_如何学编程del.Trx, indication.Model.ShockBpsDropList.Value, indication.Model.ShockIncrements.Value);
return View(@"~\Views\Indications\TermSheetViews\Swap\PrePayment.aspx", resultsList);
- This compiles but, can I do this?
I need to work with this list in javascript, I have code on another page that gets the list in Json from AJAX but in this case I don't have the ability to do that. How would I then work with the list that I am passing in through javascript, with the following method:
CreateShockTable(data.prepaymentList, "TotalValueString", "#valueTable", "Prepayment Value");
That prepaymentList
is this list.
You could serialize the model into a JSON object using JavaScriptSerializer:
<script type="text/javascript">
var prepaymentList = <%= new JavaScriptSerializer().Serialize(Model) %>;
// TODO: use the list here, for example pass it to some function:
CreateShockTable(
prepaymentList,
"TotalValueString",
"#valueTable",
"Prepayment Value"
);
</script>
Yes, you can.
var myList = ViewData["whatever"] as List<Indications.Analysis.PrepaymentResult>;
It is translated into JSON Array during serialization, so you can easily loop through it. I don't clearly understand what do you mean by "passing in through javascript". Is it a result of the action called through Ajax?
精彩评论