首页 > 代码库 > ActionResult

ActionResult

MVC 中有许多自定义的 ActionResult,

 

自定义 ActionResult 的方法是继承 ActionResult,如下例:

public class XmlResult : ActionResult{    // Properties    public XDocument Data { get; set; }    public bool Rss { get; set; }    public XmlResult(XDocument data, bool rss = false)    {        Data = http://www.mamicode.com/data;"context");        }        if (string.IsNullOrEmpty(Data.Declaration.Encoding))        {            Data.Declaration.Encoding = Encoding.UTF8.WebName; //Default encoding        }        HttpResponseBase response = context.HttpContext.Response;        response.ClearContent();        response.ContentType = Rss ? "application/rss+xml" : "application/xml";        response.ContentEncoding = Encoding.GetEncoding(Data.Declaration.Encoding);        if (Data != null)        {            Data.Save(response.OutputStream);        }        response.Flush();        response.End();    }}

  

ActionResult