This is an extension of Redirect. Namespace System. Web. Mvc
{
Using System;
/// <Summary>
/// Extension of the Controller Redirect operation
// Blog: http://chsword.cnblogs.com/
/// </Summary>
Public static class RedirectExtension
{
/// <Summary>
/// Redirect to the previous Action. That is, the header's "HTTP_REFERER" (<c> Context. UrlReferrer </c> ).
/// </Summary>
Static public void RedirectToReferrer (this Controller controller ){
Controller. Response. Redirect (controller. Request. ServerVariables ["HTTP_REFERER"]);
}
[Obsolete ("expired please use RedirectToReferrer")]
Static public void RedirectToReferer (this Controller controller)
{
RedirectToReferrer (controller );
}
/// <Summary>
/// Redirect to the site root directory (<c> Context. ApplicationPath + "/" </c> ).
/// </Summary>
Static public void RedirectToSiteRoot (this Controller controller ){
Controller. Response. Redirect (controller. Request. ApplicationPath + "/");
}
}
}
Pv3 already exists, but it is not supported by void, but it still has its availability.
Namespace System. Web. Mvc
{
Using System;
Using System. Text;
Using System. Web. Script. Serialization;
Using System. Runtime. Serialization. Json;
/// <Summary>
/// Extension of RenderView
// Blog: http://chsword.cnblogs.com/
/// </Summary>
Static public class RenderExtension
{
/// <Summary>
/// Display the text to be displayed
/// </Summary>
/// <Param name = "c"> </param>
/// <Param name = "str"> text content </param>
[Obsolete ("used only in Asp.net Mvc Preview2, and a new method Content is provided in PV3")]
Static public void RenderText (this Controller c, string str)
{
C. HttpContext. Response. Write (str );
}
/// <Summary>
/// Return the object to be displayed in JSON to the client
/// </Summary>
/// <Param name = "c"> </param>
/// <Param name = "data"> object to be sent </param>
[Obsolete ("used only in Asp.net Mvc Preview2, and a new method Json is provided in PV3")]
Public static void RenderJSON (this Controller c, object data)
{
C. RenderJSON (data, null );
}
/// <Summary>
/// Return the object to be displayed in JSON to the client
/// </Summary>
/// <Param name = "c"> </param>
/// <Param name = "data"> object to be sent </param>
/// <Param name = "contenttype"> the default Content-Type transmitted is application/json. </param>
[Obsolete ("used only in Asp.net Mvc Preview2, and a new method Json is provided in PV3")]
Public static void RenderJSON (this Controller c, object data, string contenttype)
{
C. RenderJSON (data, contentType, null );
}
/// <Summary>
/// Return the object to be displayed in JSON to the client
/// </Summary>
/// <Param name = "c"> </param>
/// <Param name = "data"> object to be sent </param>
/// <Param name = "contenttype"> If the transmitted Content-Type is null, the default value is application/json. </param>
/// <Param name = "encoding"> encoding method </param>
[Obsolete ("used only in Asp.net Mvc Preview2, and a new method Json is provided in PV3")]
Public static void RenderJSON (this Controller c, object data, string contenttype, Encoding encoding)
{
HttpResponseBase response = c. HttpContext. Response;
If (! String. IsNullOrEmpty (contenttype ))
{
Response. ContentType = contenttype;
}
Else
{
Response. ContentType = "application/json ";
}
If (encoding! = Null)
{
Response. ContentEncoding = encoding;
}
If (data! = Null)
{
DataContractJsonSerializer sr = new DataContractJsonSerializer (typeof (object ));
Sr. WriteObject (response. OutputStream, data );
}
}
}
}