1

I am submitting a form that passes three values to the controller, which are email, fullname and id fields.

 @using (Html.BeginForm("SubmitResult", "TestAPI", FormMethod.Post, new { id = "postEmailForm" }))    
{
    <div id="details-container">
        <input type="text" name="email" />
        <input type="text" name="fullName" />
        <input type="text" name="studentId" />

        <button type="submit" id="send">Send</button>
    </div>
}   

Controller:

  [HttpPost("SubmitResult/{email}/{fullName}/{studentId}")]
    [Authorize(Roles = "Admin, Shop")]
    public IActionResult SubmitResult(string email, string fullName, long? studentId)
    {
    }

However, when I click on submit button, it throws an error message in the console.

OPTIONS https://localhost:50138/TestAPI/SubmitResult net::ERR_SSL_PROTOCOL_ERROR.

Headers:

Request URL: https://localhost:50138/TestAPI/SubmitResult

Referrer Policy: no-referrer-when-downgrade

How do I properly decorate the attribute in the controller, so I can pass multiple parameters to test API using Postman?

I was expecting something like below to work for testing.

http://localhost:50138/api/TestAPI/SubmitResult/[email protected]/MikeShawn/2

2
  • So is that ASP.NET Core application or ASP.NET Web Api? Your tags are confusing because it is not the same. Commented May 12, 2017 at 20:46
  • Sorry edited. It is asp.net core app Commented May 12, 2017 at 20:47

1 Answer 1

1

There are few issues with your code.

First issue is that it looks like when you post the data it tries to send it using a cross-origin request. If this is on purpose then you have to add CORS middleware in your pipe. If not - you have to figure out why it happens and fix it. There are not enough details in your question to say why it happens.

Two URLs have the same origin if they have identical schemes, hosts, and ports.

Second issue is that you are trying to send data by adding parameters to URL. This is wrong because the data will be sent in the request body. So regarding HttpPost attribute it should look like this:

[HttpPost]
[Authorize(Roles = "Admin, Shop")]
public IActionResult SubmitResult(string email, string fullName, long? studentId)
{
}

UPDATE

Just looked at your question again. It seems the page with form itself was opened using http scheme, but the POST request is actually going to https scheme. So to resolve first issue make sure that page with form is loaded using https scheme too.

Sign up to request clarification or add additional context in comments.

1 Comment

I have just updated my answer and removed third and fourth issues as they are not relevant to your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.