How can I extend and add to the IFormFile Interface in .NET Core. Need to append data to the serialised array...











up vote
1
down vote

favorite












I need to upload a file using .net core.



I am using a multipart form and AJAX.



However I have a unique requirement. I need to be able to add data to the serialized array and then bind it to the controller through an ajax POST request and Model Binding.



I need to add an id, which i pass to the controller. Based on the id I decide to which row in a table I save the uploaded file details.



My Controller to which I am Posting:



 [HttpPost]
public async Task<IActionResult> File(List<IFormFile> files)
{
long size = files.Sum(f => f.Length);


var filePath = Path.GetTempFileName();


foreach (var formFile in files)
{
if (formFile.Length > 0)
{
using (var stream = new FileStream(filePath, FileMode.Create))
{
await formFile.CopyToAsync(stream);
}
}
}

string fpath = filePath;

var query = from d in db.TableA
where d.File == null && d.id == id // This is where I need to compare the ID
select d;


foreach (TableA details in query)
{
details.File = filePath;
}
try
{
await db.SaveChangesAsync(); // await needed to hold execution
}
catch (Exception e)
{
Console.WriteLine(e);

}


return RedirectToAction("View");
}



where d.File == null && d.id == id // This is where I need to compare
the ID




Multi Part Form:



<form method="post" id="typea" enctype="multipart/form-data" asp-controller="Main" asp-action="File">
<label class="btn btn-info"> Upload your document <input type="file" name="files" onchange="this.form.submit()" hidden />
</label>
</form>


My Ajax call:



 $(document).ready(function () {
$('#typea').click(function () {


event.preventDefault();


var $form = $(this);
var serializedData = $form.serializeArray();
serializedData.push({ name: "ID", value: "typea" });
$.ajax({
url: "Main/File",
type: "POST",
data: serializedData

});

});


My problem is this:



If i push the array I cannot count on IFormFile Interface for model binding.



Can I somehow extend the IFormFIle interface?



Or is there a way I can do it without using the IFormFile.
I tried to write my own model referencing from the IFormFIle interface but could not.



public interface IFormFile
{
string ContentType { get; }
string ContentDisposition { get; }
IHeaderDictionary Headers { get; }
long Length { get; }
string Name { get; }
string FileName { get; }
Stream OpenReadStream();
void CopyTo(Stream target);
Task CopyToAsync(Stream target, CancellationToken cancellationToken = null);
}


I could not use the methods of the interface, which is obvious.
Pointers please :).










share|improve this question


























    up vote
    1
    down vote

    favorite












    I need to upload a file using .net core.



    I am using a multipart form and AJAX.



    However I have a unique requirement. I need to be able to add data to the serialized array and then bind it to the controller through an ajax POST request and Model Binding.



    I need to add an id, which i pass to the controller. Based on the id I decide to which row in a table I save the uploaded file details.



    My Controller to which I am Posting:



     [HttpPost]
    public async Task<IActionResult> File(List<IFormFile> files)
    {
    long size = files.Sum(f => f.Length);


    var filePath = Path.GetTempFileName();


    foreach (var formFile in files)
    {
    if (formFile.Length > 0)
    {
    using (var stream = new FileStream(filePath, FileMode.Create))
    {
    await formFile.CopyToAsync(stream);
    }
    }
    }

    string fpath = filePath;

    var query = from d in db.TableA
    where d.File == null && d.id == id // This is where I need to compare the ID
    select d;


    foreach (TableA details in query)
    {
    details.File = filePath;
    }
    try
    {
    await db.SaveChangesAsync(); // await needed to hold execution
    }
    catch (Exception e)
    {
    Console.WriteLine(e);

    }


    return RedirectToAction("View");
    }



    where d.File == null && d.id == id // This is where I need to compare
    the ID




    Multi Part Form:



    <form method="post" id="typea" enctype="multipart/form-data" asp-controller="Main" asp-action="File">
    <label class="btn btn-info"> Upload your document <input type="file" name="files" onchange="this.form.submit()" hidden />
    </label>
    </form>


    My Ajax call:



     $(document).ready(function () {
    $('#typea').click(function () {


    event.preventDefault();


    var $form = $(this);
    var serializedData = $form.serializeArray();
    serializedData.push({ name: "ID", value: "typea" });
    $.ajax({
    url: "Main/File",
    type: "POST",
    data: serializedData

    });

    });


    My problem is this:



    If i push the array I cannot count on IFormFile Interface for model binding.



    Can I somehow extend the IFormFIle interface?



    Or is there a way I can do it without using the IFormFile.
    I tried to write my own model referencing from the IFormFIle interface but could not.



    public interface IFormFile
    {
    string ContentType { get; }
    string ContentDisposition { get; }
    IHeaderDictionary Headers { get; }
    long Length { get; }
    string Name { get; }
    string FileName { get; }
    Stream OpenReadStream();
    void CopyTo(Stream target);
    Task CopyToAsync(Stream target, CancellationToken cancellationToken = null);
    }


    I could not use the methods of the interface, which is obvious.
    Pointers please :).










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I need to upload a file using .net core.



      I am using a multipart form and AJAX.



      However I have a unique requirement. I need to be able to add data to the serialized array and then bind it to the controller through an ajax POST request and Model Binding.



      I need to add an id, which i pass to the controller. Based on the id I decide to which row in a table I save the uploaded file details.



      My Controller to which I am Posting:



       [HttpPost]
      public async Task<IActionResult> File(List<IFormFile> files)
      {
      long size = files.Sum(f => f.Length);


      var filePath = Path.GetTempFileName();


      foreach (var formFile in files)
      {
      if (formFile.Length > 0)
      {
      using (var stream = new FileStream(filePath, FileMode.Create))
      {
      await formFile.CopyToAsync(stream);
      }
      }
      }

      string fpath = filePath;

      var query = from d in db.TableA
      where d.File == null && d.id == id // This is where I need to compare the ID
      select d;


      foreach (TableA details in query)
      {
      details.File = filePath;
      }
      try
      {
      await db.SaveChangesAsync(); // await needed to hold execution
      }
      catch (Exception e)
      {
      Console.WriteLine(e);

      }


      return RedirectToAction("View");
      }



      where d.File == null && d.id == id // This is where I need to compare
      the ID




      Multi Part Form:



      <form method="post" id="typea" enctype="multipart/form-data" asp-controller="Main" asp-action="File">
      <label class="btn btn-info"> Upload your document <input type="file" name="files" onchange="this.form.submit()" hidden />
      </label>
      </form>


      My Ajax call:



       $(document).ready(function () {
      $('#typea').click(function () {


      event.preventDefault();


      var $form = $(this);
      var serializedData = $form.serializeArray();
      serializedData.push({ name: "ID", value: "typea" });
      $.ajax({
      url: "Main/File",
      type: "POST",
      data: serializedData

      });

      });


      My problem is this:



      If i push the array I cannot count on IFormFile Interface for model binding.



      Can I somehow extend the IFormFIle interface?



      Or is there a way I can do it without using the IFormFile.
      I tried to write my own model referencing from the IFormFIle interface but could not.



      public interface IFormFile
      {
      string ContentType { get; }
      string ContentDisposition { get; }
      IHeaderDictionary Headers { get; }
      long Length { get; }
      string Name { get; }
      string FileName { get; }
      Stream OpenReadStream();
      void CopyTo(Stream target);
      Task CopyToAsync(Stream target, CancellationToken cancellationToken = null);
      }


      I could not use the methods of the interface, which is obvious.
      Pointers please :).










      share|improve this question













      I need to upload a file using .net core.



      I am using a multipart form and AJAX.



      However I have a unique requirement. I need to be able to add data to the serialized array and then bind it to the controller through an ajax POST request and Model Binding.



      I need to add an id, which i pass to the controller. Based on the id I decide to which row in a table I save the uploaded file details.



      My Controller to which I am Posting:



       [HttpPost]
      public async Task<IActionResult> File(List<IFormFile> files)
      {
      long size = files.Sum(f => f.Length);


      var filePath = Path.GetTempFileName();


      foreach (var formFile in files)
      {
      if (formFile.Length > 0)
      {
      using (var stream = new FileStream(filePath, FileMode.Create))
      {
      await formFile.CopyToAsync(stream);
      }
      }
      }

      string fpath = filePath;

      var query = from d in db.TableA
      where d.File == null && d.id == id // This is where I need to compare the ID
      select d;


      foreach (TableA details in query)
      {
      details.File = filePath;
      }
      try
      {
      await db.SaveChangesAsync(); // await needed to hold execution
      }
      catch (Exception e)
      {
      Console.WriteLine(e);

      }


      return RedirectToAction("View");
      }



      where d.File == null && d.id == id // This is where I need to compare
      the ID




      Multi Part Form:



      <form method="post" id="typea" enctype="multipart/form-data" asp-controller="Main" asp-action="File">
      <label class="btn btn-info"> Upload your document <input type="file" name="files" onchange="this.form.submit()" hidden />
      </label>
      </form>


      My Ajax call:



       $(document).ready(function () {
      $('#typea').click(function () {


      event.preventDefault();


      var $form = $(this);
      var serializedData = $form.serializeArray();
      serializedData.push({ name: "ID", value: "typea" });
      $.ajax({
      url: "Main/File",
      type: "POST",
      data: serializedData

      });

      });


      My problem is this:



      If i push the array I cannot count on IFormFile Interface for model binding.



      Can I somehow extend the IFormFIle interface?



      Or is there a way I can do it without using the IFormFile.
      I tried to write my own model referencing from the IFormFIle interface but could not.



      public interface IFormFile
      {
      string ContentType { get; }
      string ContentDisposition { get; }
      IHeaderDictionary Headers { get; }
      long Length { get; }
      string Name { get; }
      string FileName { get; }
      Stream OpenReadStream();
      void CopyTo(Stream target);
      Task CopyToAsync(Stream target, CancellationToken cancellationToken = null);
      }


      I could not use the methods of the interface, which is obvious.
      Pointers please :).







      jquery asp.net ajax asp.net-core model-binding






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 at 19:31









      Abhilash Gopalakrishna

      10912




      10912
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted












          1. You don't need to implements (extends) the IFormFile interface, a wrapper by composition is preferred over inheritance. Simply create a dummy POCO to hold the information :



            public class IFormFilesWrapper{

            public string Id {get;set;} // you might change the type to Guid / int /e.t.c

            public IList<IFormFile> Files {get;set;}
            }


            and the action method will be :



            [HttpPost]
            public async Task<IActionResult> File(IFormFilesWrapper filesWrapper)
            {
            var id = filesWrapper.Id; // here's the Id posted by client

            long size = filesWrapper.Files.Sum(f => f.Length);

            var filePath = Path.GetTempFileName();

            foreach (var formFile in filesWrapper.Files)
            {
            if (formFile.Length > 0)
            {
            using (var stream = new FileStream(filePath, FileMode.Create))
            {
            await formFile.CopyToAsync(stream);
            }
            }
            }

            // ...
            }



          2. As a side note, if I remember correctly, the $form.serializeArray() doesn't work well for multipart/form-data. So I use a plain FormData to generate the payload :



            $(document).ready(function () {
            $('#typea>button').click(function () {

            event.preventDefault();

            var form = document.querySelector("#typea");
            var formData = new FormData(form);
            formData.append("ID","typea");

            var xhr = new XMLHttpRequest();
            xhr.open("POST","Main/File");
            xhr.send(formData);
            });
            });



          A screenshot :



          enter image description here






          share|improve this answer





















          • @it,inus Hi, The above solution worked spledidly, thank you. However it worked only for one submission. Therefore I have removed it outside document.ready() and attached it to a submit handler. Now I am getting an error saying "Content" attribute of windows object is depreciated. This is what i have done:
            – Abhilash Gopalakrishna
            Nov 19 at 10:34






          • 1




            @AbhilashGopalakrishna, don't submit the form, simply add a button and use it to trigger ajax : document.querySelector("#your_button").onclick= function(){ /* ... */ }
            – itminus
            Nov 19 at 10:54






          • 1




            @AbhilashGopalakrishna If you still cannot figure it out , please feel free to comment; or when I can access my desktop tomorrow , I'll show you a complete code.
            – itminus
            Nov 19 at 10:58






          • 1




            @AbhilashGopalakrishna, if you submit the form , the server will response with a new page. So It's better to use ajax to post the payload to server, namely use the code var form = document.querySelector("#typea"); var formData = new FormData(form); formData.append("ID","typea"); var xhr = new XMLHttpRequest(); xhr.open("POST","Main/File"); xhr.send(formData);
            – itminus
            Nov 19 at 11:44






          • 1




            Let us continue this discussion in chat.
            – itminus
            Nov 19 at 11:44











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364683%2fhow-can-i-extend-and-add-to-the-iformfile-interface-in-net-core-need-to-append%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted












          1. You don't need to implements (extends) the IFormFile interface, a wrapper by composition is preferred over inheritance. Simply create a dummy POCO to hold the information :



            public class IFormFilesWrapper{

            public string Id {get;set;} // you might change the type to Guid / int /e.t.c

            public IList<IFormFile> Files {get;set;}
            }


            and the action method will be :



            [HttpPost]
            public async Task<IActionResult> File(IFormFilesWrapper filesWrapper)
            {
            var id = filesWrapper.Id; // here's the Id posted by client

            long size = filesWrapper.Files.Sum(f => f.Length);

            var filePath = Path.GetTempFileName();

            foreach (var formFile in filesWrapper.Files)
            {
            if (formFile.Length > 0)
            {
            using (var stream = new FileStream(filePath, FileMode.Create))
            {
            await formFile.CopyToAsync(stream);
            }
            }
            }

            // ...
            }



          2. As a side note, if I remember correctly, the $form.serializeArray() doesn't work well for multipart/form-data. So I use a plain FormData to generate the payload :



            $(document).ready(function () {
            $('#typea>button').click(function () {

            event.preventDefault();

            var form = document.querySelector("#typea");
            var formData = new FormData(form);
            formData.append("ID","typea");

            var xhr = new XMLHttpRequest();
            xhr.open("POST","Main/File");
            xhr.send(formData);
            });
            });



          A screenshot :



          enter image description here






          share|improve this answer





















          • @it,inus Hi, The above solution worked spledidly, thank you. However it worked only for one submission. Therefore I have removed it outside document.ready() and attached it to a submit handler. Now I am getting an error saying "Content" attribute of windows object is depreciated. This is what i have done:
            – Abhilash Gopalakrishna
            Nov 19 at 10:34






          • 1




            @AbhilashGopalakrishna, don't submit the form, simply add a button and use it to trigger ajax : document.querySelector("#your_button").onclick= function(){ /* ... */ }
            – itminus
            Nov 19 at 10:54






          • 1




            @AbhilashGopalakrishna If you still cannot figure it out , please feel free to comment; or when I can access my desktop tomorrow , I'll show you a complete code.
            – itminus
            Nov 19 at 10:58






          • 1




            @AbhilashGopalakrishna, if you submit the form , the server will response with a new page. So It's better to use ajax to post the payload to server, namely use the code var form = document.querySelector("#typea"); var formData = new FormData(form); formData.append("ID","typea"); var xhr = new XMLHttpRequest(); xhr.open("POST","Main/File"); xhr.send(formData);
            – itminus
            Nov 19 at 11:44






          • 1




            Let us continue this discussion in chat.
            – itminus
            Nov 19 at 11:44















          up vote
          1
          down vote



          accepted












          1. You don't need to implements (extends) the IFormFile interface, a wrapper by composition is preferred over inheritance. Simply create a dummy POCO to hold the information :



            public class IFormFilesWrapper{

            public string Id {get;set;} // you might change the type to Guid / int /e.t.c

            public IList<IFormFile> Files {get;set;}
            }


            and the action method will be :



            [HttpPost]
            public async Task<IActionResult> File(IFormFilesWrapper filesWrapper)
            {
            var id = filesWrapper.Id; // here's the Id posted by client

            long size = filesWrapper.Files.Sum(f => f.Length);

            var filePath = Path.GetTempFileName();

            foreach (var formFile in filesWrapper.Files)
            {
            if (formFile.Length > 0)
            {
            using (var stream = new FileStream(filePath, FileMode.Create))
            {
            await formFile.CopyToAsync(stream);
            }
            }
            }

            // ...
            }



          2. As a side note, if I remember correctly, the $form.serializeArray() doesn't work well for multipart/form-data. So I use a plain FormData to generate the payload :



            $(document).ready(function () {
            $('#typea>button').click(function () {

            event.preventDefault();

            var form = document.querySelector("#typea");
            var formData = new FormData(form);
            formData.append("ID","typea");

            var xhr = new XMLHttpRequest();
            xhr.open("POST","Main/File");
            xhr.send(formData);
            });
            });



          A screenshot :



          enter image description here






          share|improve this answer





















          • @it,inus Hi, The above solution worked spledidly, thank you. However it worked only for one submission. Therefore I have removed it outside document.ready() and attached it to a submit handler. Now I am getting an error saying "Content" attribute of windows object is depreciated. This is what i have done:
            – Abhilash Gopalakrishna
            Nov 19 at 10:34






          • 1




            @AbhilashGopalakrishna, don't submit the form, simply add a button and use it to trigger ajax : document.querySelector("#your_button").onclick= function(){ /* ... */ }
            – itminus
            Nov 19 at 10:54






          • 1




            @AbhilashGopalakrishna If you still cannot figure it out , please feel free to comment; or when I can access my desktop tomorrow , I'll show you a complete code.
            – itminus
            Nov 19 at 10:58






          • 1




            @AbhilashGopalakrishna, if you submit the form , the server will response with a new page. So It's better to use ajax to post the payload to server, namely use the code var form = document.querySelector("#typea"); var formData = new FormData(form); formData.append("ID","typea"); var xhr = new XMLHttpRequest(); xhr.open("POST","Main/File"); xhr.send(formData);
            – itminus
            Nov 19 at 11:44






          • 1




            Let us continue this discussion in chat.
            – itminus
            Nov 19 at 11:44













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted








          1. You don't need to implements (extends) the IFormFile interface, a wrapper by composition is preferred over inheritance. Simply create a dummy POCO to hold the information :



            public class IFormFilesWrapper{

            public string Id {get;set;} // you might change the type to Guid / int /e.t.c

            public IList<IFormFile> Files {get;set;}
            }


            and the action method will be :



            [HttpPost]
            public async Task<IActionResult> File(IFormFilesWrapper filesWrapper)
            {
            var id = filesWrapper.Id; // here's the Id posted by client

            long size = filesWrapper.Files.Sum(f => f.Length);

            var filePath = Path.GetTempFileName();

            foreach (var formFile in filesWrapper.Files)
            {
            if (formFile.Length > 0)
            {
            using (var stream = new FileStream(filePath, FileMode.Create))
            {
            await formFile.CopyToAsync(stream);
            }
            }
            }

            // ...
            }



          2. As a side note, if I remember correctly, the $form.serializeArray() doesn't work well for multipart/form-data. So I use a plain FormData to generate the payload :



            $(document).ready(function () {
            $('#typea>button').click(function () {

            event.preventDefault();

            var form = document.querySelector("#typea");
            var formData = new FormData(form);
            formData.append("ID","typea");

            var xhr = new XMLHttpRequest();
            xhr.open("POST","Main/File");
            xhr.send(formData);
            });
            });



          A screenshot :



          enter image description here






          share|improve this answer














          1. You don't need to implements (extends) the IFormFile interface, a wrapper by composition is preferred over inheritance. Simply create a dummy POCO to hold the information :



            public class IFormFilesWrapper{

            public string Id {get;set;} // you might change the type to Guid / int /e.t.c

            public IList<IFormFile> Files {get;set;}
            }


            and the action method will be :



            [HttpPost]
            public async Task<IActionResult> File(IFormFilesWrapper filesWrapper)
            {
            var id = filesWrapper.Id; // here's the Id posted by client

            long size = filesWrapper.Files.Sum(f => f.Length);

            var filePath = Path.GetTempFileName();

            foreach (var formFile in filesWrapper.Files)
            {
            if (formFile.Length > 0)
            {
            using (var stream = new FileStream(filePath, FileMode.Create))
            {
            await formFile.CopyToAsync(stream);
            }
            }
            }

            // ...
            }



          2. As a side note, if I remember correctly, the $form.serializeArray() doesn't work well for multipart/form-data. So I use a plain FormData to generate the payload :



            $(document).ready(function () {
            $('#typea>button').click(function () {

            event.preventDefault();

            var form = document.querySelector("#typea");
            var formData = new FormData(form);
            formData.append("ID","typea");

            var xhr = new XMLHttpRequest();
            xhr.open("POST","Main/File");
            xhr.send(formData);
            });
            });



          A screenshot :



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 6:40









          itminus

          2,3961217




          2,3961217












          • @it,inus Hi, The above solution worked spledidly, thank you. However it worked only for one submission. Therefore I have removed it outside document.ready() and attached it to a submit handler. Now I am getting an error saying "Content" attribute of windows object is depreciated. This is what i have done:
            – Abhilash Gopalakrishna
            Nov 19 at 10:34






          • 1




            @AbhilashGopalakrishna, don't submit the form, simply add a button and use it to trigger ajax : document.querySelector("#your_button").onclick= function(){ /* ... */ }
            – itminus
            Nov 19 at 10:54






          • 1




            @AbhilashGopalakrishna If you still cannot figure it out , please feel free to comment; or when I can access my desktop tomorrow , I'll show you a complete code.
            – itminus
            Nov 19 at 10:58






          • 1




            @AbhilashGopalakrishna, if you submit the form , the server will response with a new page. So It's better to use ajax to post the payload to server, namely use the code var form = document.querySelector("#typea"); var formData = new FormData(form); formData.append("ID","typea"); var xhr = new XMLHttpRequest(); xhr.open("POST","Main/File"); xhr.send(formData);
            – itminus
            Nov 19 at 11:44






          • 1




            Let us continue this discussion in chat.
            – itminus
            Nov 19 at 11:44


















          • @it,inus Hi, The above solution worked spledidly, thank you. However it worked only for one submission. Therefore I have removed it outside document.ready() and attached it to a submit handler. Now I am getting an error saying "Content" attribute of windows object is depreciated. This is what i have done:
            – Abhilash Gopalakrishna
            Nov 19 at 10:34






          • 1




            @AbhilashGopalakrishna, don't submit the form, simply add a button and use it to trigger ajax : document.querySelector("#your_button").onclick= function(){ /* ... */ }
            – itminus
            Nov 19 at 10:54






          • 1




            @AbhilashGopalakrishna If you still cannot figure it out , please feel free to comment; or when I can access my desktop tomorrow , I'll show you a complete code.
            – itminus
            Nov 19 at 10:58






          • 1




            @AbhilashGopalakrishna, if you submit the form , the server will response with a new page. So It's better to use ajax to post the payload to server, namely use the code var form = document.querySelector("#typea"); var formData = new FormData(form); formData.append("ID","typea"); var xhr = new XMLHttpRequest(); xhr.open("POST","Main/File"); xhr.send(formData);
            – itminus
            Nov 19 at 11:44






          • 1




            Let us continue this discussion in chat.
            – itminus
            Nov 19 at 11:44
















          @it,inus Hi, The above solution worked spledidly, thank you. However it worked only for one submission. Therefore I have removed it outside document.ready() and attached it to a submit handler. Now I am getting an error saying "Content" attribute of windows object is depreciated. This is what i have done:
          – Abhilash Gopalakrishna
          Nov 19 at 10:34




          @it,inus Hi, The above solution worked spledidly, thank you. However it worked only for one submission. Therefore I have removed it outside document.ready() and attached it to a submit handler. Now I am getting an error saying "Content" attribute of windows object is depreciated. This is what i have done:
          – Abhilash Gopalakrishna
          Nov 19 at 10:34




          1




          1




          @AbhilashGopalakrishna, don't submit the form, simply add a button and use it to trigger ajax : document.querySelector("#your_button").onclick= function(){ /* ... */ }
          – itminus
          Nov 19 at 10:54




          @AbhilashGopalakrishna, don't submit the form, simply add a button and use it to trigger ajax : document.querySelector("#your_button").onclick= function(){ /* ... */ }
          – itminus
          Nov 19 at 10:54




          1




          1




          @AbhilashGopalakrishna If you still cannot figure it out , please feel free to comment; or when I can access my desktop tomorrow , I'll show you a complete code.
          – itminus
          Nov 19 at 10:58




          @AbhilashGopalakrishna If you still cannot figure it out , please feel free to comment; or when I can access my desktop tomorrow , I'll show you a complete code.
          – itminus
          Nov 19 at 10:58




          1




          1




          @AbhilashGopalakrishna, if you submit the form , the server will response with a new page. So It's better to use ajax to post the payload to server, namely use the code var form = document.querySelector("#typea"); var formData = new FormData(form); formData.append("ID","typea"); var xhr = new XMLHttpRequest(); xhr.open("POST","Main/File"); xhr.send(formData);
          – itminus
          Nov 19 at 11:44




          @AbhilashGopalakrishna, if you submit the form , the server will response with a new page. So It's better to use ajax to post the payload to server, namely use the code var form = document.querySelector("#typea"); var formData = new FormData(form); formData.append("ID","typea"); var xhr = new XMLHttpRequest(); xhr.open("POST","Main/File"); xhr.send(formData);
          – itminus
          Nov 19 at 11:44




          1




          1




          Let us continue this discussion in chat.
          – itminus
          Nov 19 at 11:44




          Let us continue this discussion in chat.
          – itminus
          Nov 19 at 11:44


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364683%2fhow-can-i-extend-and-add-to-the-iformfile-interface-in-net-core-need-to-append%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga