Empty first line in razor mvc 4 rc
asp.net-mvc-4, razor
Solution
Temporary fix? ActionFilter and strip out the empty first line? Clearly you could also do other minification on the response if suitable.
public class TranslationFilter : MemoryStream
{
private Stream filter = null;
public TranslationFilter(HttpResponseBase httpResponseBase)
{
filter = httpResponseBase.Filter;
}
public override void Write(byte[] buffer, int offset, int count)
{
var response = UTF8Encoding.UTF8.GetString(buffer);
// remove all newlines
response = response.Replace(System.Environment.NewLine, "");
/* remove just first empty line
if (response.Substring(0, 2) == "\r\n")
{
response = response.Substring(2, response.Length - 2);
} */
filter.Write(UTF8Encoding.UTF8.GetBytes(response), offset, UTF8Encoding.UTF8.GetByteCount(response));
}
}
public class ResponseFilter : ActionFilterAttribute
{
public ResponseFilter()
{
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
base.OnResultExecuted(filterContext);
filterContext.HttpContext.Response.Filter = new TranslationFilter(filterContext.HttpContext.Response);
}
}
And add it onto the Controller method?
[ResponseFilter]
public ActionResult Index()
{
return View();
}
Problem
I've migrated from mvc 3 to mvc 4 and encountered with the following problem. ``` @using InvoiceDocflow.Controllers @{ Response.ContentType = "text/xml"; } <?xml version="1.1" encoding="UTF-8" ?> <dc> @foreach (var dcLink in (IEnumerable<DcLink>)ViewData["SupportedDcs"]) { <link rel="@dcLink.RelUri.ToString()" href="@dcLink.DcUri.ToString()" /> } </dc> ``` This is my view. My layout is just one line ``` @RenderBody() ``` So in mvc 3 `<?xml version="1.1" encoding="UTF-8" ?>` appeared in the first line, but now, its appears on the second line, leaving th first line empty. Can I make it render on the first line as it was in mvc 3? By the way. ``` @using InvoiceDocflow.Controllers @{ Response.ContentType = "text/xml"; }<?xml version="1.1" encoding="UTF-8" ?> ``` This would work, but this is not what I whant to do at all.