Asp.net MVC Vue Axios无刷新请求数据和响应数据
Model层Region.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1.Models { public class Region { public int Id { get; set; } public string City { get; set; } } }
Controller
using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using WebApplication1.Models; namespace WebApplication1.Controllers { public class DefaultController : Controller { //获取Json数据 [HttpPost] public JsonResult GetJson(int id) { List<Region> regions = new List<Region>() { new Region{ Id=0,City="山东省"}, new Region{ Id=1,City="济南市"}, new Region{ Id=2,City="历下区"}, new Region{ Id=3,City="市中区"}, new Region{ Id=4,City="天桥区"}, new Region{ Id=5,City="槐荫区"} }; var json = from r in regions where r.Id == id select r; return Json(json); } //显示主页 public ActionResult Index() { return View(); } } }