Working example for JavaScriptResult in asp.net mvc

前端 未结 3 2031
梦谈多话
梦谈多话 2020-12-01 16:05

Can somebody provide a working example of JavaScriptResult in asp.net mvc. I understand that it returns javascript which is then executed on the client side and also that th

3条回答
  •  既然无缘
    2020-12-01 16:53

    Check out my reply in this post;

    MVC how to return instruction to run javascipt method?

    That will return a partial view to the page. If you want to itterate through a json object then return a json object from your controller and use something like the following;

    var obj = eval('(' + msg + ')');
    

    msg above is the returned object from your controller;

    then,

    $.each(obj.Objects, function() { do something with object });
    

    "Objects" above is a property within the returned json object.

    So in c#

    public class JsonObject()
    {
      List Objects{get;set;}
    }
    

    Return the above object to the view.

    Does this make sense or would you like a working sample?

提交回复
热议问题