I tried the below alternative code in webapi controller but couldnt see a downloading file once I call this

public HttpResponseMessage ModelExport(Guid id) {

        var lst = Repository.All<Model>(i => i.ModelConstants, i => i.QualitativeDiscretes
            , i => i.QualitativeDiscretes.Select(x => x.QualitativeDiscreteLevels)
            , i => i.QuantitativeDiscretes
            , i => i.QuantitativeDiscretes.Select(x => x.QuantitativeDiscreteLevels)).Where(m => m.Id == id).FirstOrDefault();
        var str = Serializable.SerializeObject(lst);

        var result = Request.CreateResponse(HttpStatusCode.OK);
        var builder = new StringBuilder();
        using (var writer = new StringWriter(builder))
        {

            result.Content = new StringContent(str, Encoding.UTF8, "application/xml");
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = string.Format("model.xml")
            };
             return result;
        }
        //return ResponseMessage(result);
    }

Related posts

Recent Viewed