예제 #1
0
        public HttpResponseMessage Post(string city, string keyword)
        {
            if (keyword == null)
            {
                keyword = "";
            }
            var result = db.APIsearch(Convert.ToInt32(city), 1, keyword).ToList();
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
            string viewPath   = HttpContext.Current.Server.MapPath(@"~/Views/API/APIresultNhaHang1.cshtml");
            var    template   = File.ReadAllText(viewPath);
            string parsedView = Razor.Parse(template, result);

            //response kèm luôn encode và type, nếu set riêng dễ lỗi
            response.Content = new StringContent(parsedView, System.Text.Encoding.UTF8, "text/html");
            //response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html;charset=utf-8");
            //response.Headers.CacheControl = new System.Net.Http.Headers.CacheControlHeaderValue()
            return(response);
        }