Convert .Net object to JSON object in the view

后端 未结 3 1971
一整个雨季
一整个雨季 2020-12-24 07:26

I want to convert a .Net object in to JSON in the view. My view model is like this,

public class ViewModel{
    public SearchResult SearchResult { get; set;}         


        
3条回答
  •  清酒与你
    2020-12-24 07:31

    This is an update to my original answer and I'll admit that as a result of the insistent badgering of @Tyrsius :D who refused to give up the fact that I could not access vars created in @Scripts.Render("~/bundles/homeworkflow") }

    The following code is in a separate .js file

    $(document).ready(function() {  
        alert(JSON.stringify(testVar));
    });
    

提交回复
热议问题