Search code examples
c#.net-coreasp.net-core-webapiasp.net-core-2.1

How to submit http form using C# in DOTNET CORE


I had created an HTML form using c# string builder using reference: https://stackoverflow.com/a/37757601/7961948

and in dotnet, we could submit this form using

Response.Write(formPostText);

But right now I am on DOTNET CORE 2.1 and DOTNET CORE does not support dotnet function so there is any another way to submit a form

sample code: working on dotnet version

     var formPostText = @"<html><body><div>
    <form method=""POST"" action=""OtherLogin.aspx"" name=""frm2Post"">
      <input type=""hidden"" name=""field1"" value=""" + TextBox1.Text + @""" /> 
      <input type=""hidden"" name=""field2"" value=""" + TextBox2.Text + @""" /> 
    </form></div><script type=""text/javascript"">document.frm2Post.submit();</script></body></html>
    ";

Response.Write(formPostText);

Solution

  • Dotnet core support

    var s = "some html / html form";
    
    HttpContext.Response.WriteAsync(s.ToString());
    

    Find refrence : https://gist.github.com/priore/7163408

    Is there an equivalent to "HttpContext.Response.Write" in Asp.Net Core 2?