jamheadart
jamheadart

Reputation: 5313

How do I define what is sent in a post request (ASP.NET)

I have an html form that submits a post request.

<form asp-controller="Home" asp-action="Check" method="post">
   <textarea id="uname" name="uname">myName</textarea>
   <input type="submit" name="req" value="finish" />
   <input type="submit" name="req" value="begin" />
</form>

When it submits a request using e.g. the word "myName" in the text box and the "finish" button it will send the following post request body:

uname=myName&req=finish

What I don't understand is how post requests are assembled when I push the button - how can I add more values to the request? are these all automatic? can I attach more attributes within button tags e.g. personalid="123" and send these in the request also? I'm aiming so that when I click the finish button I can send the req=finish as well as personalID=123 but I'm not sure if this is possible just by putting in more attributes.

Upvotes: 1

Views: 28

Answers (1)

SBFrancies
SBFrancies

Reputation: 4240

If the personalID is meant to be constant you could put it in a hidden field:

<input type="hidden" name="personalID" value="123"/>

If users are meant to be able to edit the id you could use a textbox:

<input type="text" name="personalID" value="123"/>

Upvotes: 1

Related Questions