0

So I am returning a view with a List as a model as such:

List<Indications.Analysis.PrepaymentResult> resultsList = Indications.Analysis.PrepaymentResult.GetPrepaymentResult(indication.Model.Trx, indication.Model.ShockBpsDropList.Value, indication.Model.ShockIncrements.Value);
return View(@"~\Views\Indications\TermSheetViews\Swap\PrePayment.aspx", resultsList);
  1. This compiles but, can I do this?
  2. 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.

1
  • I'm trying this currently by declaring it as ViewData and then passing that back. I'll let you guys know how it works out. Commented Feb 14, 2011 at 20:24

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

Comments

0
  1. Yes, you can.

    var myList = ViewData["whatever"] as List<Indications.Analysis.PrepaymentResult>;

  2. 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?

1 Comment

How would I access it though?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.