????MVC???????????????á??????????????????????????WebForm?????????????MVC??????????????°?????Ч???????????Asp.net MVC???????????????????????????????????
?????????????Asp.net MVC?г????????????????????
???????ActionResult
????ActionResult?????????Action?????????asp.net mvc????????????ActionResult??????磺ContentResult??ViewResult??JsonResult??????????????????????????Response???????????????????????????????
??????????????????XML??????????б??
????public void GetUser()
????{
????var user = new UserViewModel()
????{
????Name = "richie"??
????Age = 20??
????Email = "abc@126.com"??
????Phone = "139********"??
????Address = "my address"
????};
????XmlSerializer serializer = new XmlSerializer(typeof(UserViewModel));
????Response.ContentType = "text/xml";
????serializer.Serialize(Response.Output?? user);
????}
?????????????Controller?ж??????????????????????????????????Controller?????????????MVC?????Action????????????ActionResult????????XML???л???δ?????????????á????????????????????????XmlResult?????
????public class XmlResult : ActionResult
????{
????private object _data;
????public XmlResult(object data)
????{
????_data = data;
????}
????public override void ExecuteResult(ControllerContext context)
????{
????var serializer = new XmlSerializer(_data.GetType());
????var response = context.HttpContext.Response;
????response.ContentType = "text/xml";
????serializer.Serialize(response.Output?? _data);
????}
????}
?????????Action??????????????????
????public XmlResult GetUser()
????{
????var user = new UserViewModel()
????{
????Name = "richie"??
????Age = 20??
????Email = "abc@126.com"??
????Phone = "139********"??
????Address = "my address"
????};
????return new XmlResult(user);
????}
????????????????????????????ActionResult????????磺CsvResult???