mvc的json

虽然有许多人写过这些例子了,但毕竟这是俺自己亲自实践过的,所以在这里做些记录吧,该死的字体,又成斜体了。
服务器端如下:
 [AcceptVerbs(HttpVerbs.Get)]
      
        public JsonResult FirstMVC1()
        {
            UserTest ut = new UserTest();
            ut.TxtName = "Hello World";
                      
            
            return this.Json(ut);
        }
调用端如下:
function testJson(){
    alert("fad");
     $.getJSON("/Home/FirstMVC1/",function(data){
    
       alert(data.TxtName);
     }
    );
}
请注意我调用端,是在index页,与$.getJSON访问的不是同一个页面,usertest是一个属性类,this.json是controller自带的json转换方法,一切就是这么简单。
原文地址:https://www.cnblogs.com/chenleinet/p/1570262.html