We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

passing additional data with uploader

Thread ID:

Created:

Updated:

Platform:

Replies:

150219 Dec 26,2019 05:34 PM UTC Dec 30,2019 12:59 PM UTC ASP.NET Core - EJ 2 1
loading
Tags: File Upload
Patrick King
Asked On December 26, 2019 05:34 PM UTC

I am trying to pass additional data to and upload controller for the save process.  There are several examples I've found on the forums including

https://www.syncfusion.com/forums/137184/how-to-pass-additional-data-with-file-uploading


The examples use:
var valueFromClient = System.Web.HttpContext.Current.Request.Form.AllKeys[0]; 
var ObtainedValue = System.Web.HttpContext.Current.Request.Form[valueFromClient];

However, HttpContext is not available in asp.net core as the examples show.  Is there an example using asp.net core or some other way to handle this?

Sureshkumar P [Syncfusion]
Replied On December 30, 2019 12:59 PM UTC

Hi Patrick, 
 
Greetings from Syncfusion support. 
 
We have validated your requirement. we suspect that in HttpContext.Current was removed in ASP.NET Core. We suggest to use HttpContext.Request instead of HttpContext.Current.Request to get rid of your reported issue.  
 
Kindly refer the below code block. 
[index.html] 
 
@{ 
    var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "https://localhost:44342/Home/Save", RemoveUrl = "https://localhost:44342/Home/Remove" }; 
} 
 
@using Syncfusion.EJ2 
 
    <div class="col-lg-12 control-section" id="target"> 
        <ejs-uploader id="uploadFiles" asyncSettings="@asyncSettings" autoUpload="false" uploading="onFileUpload"></ejs-uploader> 
        
    </div> 
 
<script> 
    function onFileUpload(args) { 
        args.customFormData = [{ 'name': 'Syncfusion INC' }]; 
    }    
</script> 
 
[controller] 
 
 
using Microsoft.AspNetCore.Http; 
using Microsoft.AspNetCore.Http.Features; 
 
[AcceptVerbs("Post")] 
        public IActionResult Save(IFormCollection form) 
        { 
            string valueFromClient = Request.Form["name"]; 
            foreach (var file in form) 
            { 
                Console.WriteLine(file); 
            } 
                try 
            { 
                foreach (var file in form) 
                { 
                    if (form != null) 
                    { 
                    } 
                } 
            } 
            catch (Exception e) 
            { 
                Response.Clear(); 
                Response.ContentType = "application/json; charset=utf-8"; 
                Response.StatusCode = 204; 
                Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "No Content"; 
                Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message; 
            } 
            return Content(""); 
        } 
 
Regards, 
Sureshkumar P 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon