asp.net request.form
10,506
Your issue here is that you set the id
, and not the name
. Set the name to get the post back value. Eg:
<input type="text" name="Customerid" />
read also: HTML input - name vs. id in the line "Used on form elements to submit information"
Author by
ghost...
Updated on June 04, 2022Comments
-
ghost... almost 2 years
public ActionResult DisplayCustomer() { Customer objCustomer = new Customer(); objCustomer.Id = Convert.ToInt16(Request.Form["Customerid"]); objCustomer.CustomerCode = Request.Form["code"]; objCustomer.Amount = Convert.ToDouble(Request.Form["amount"]); return View(objCustomer); }
This is my action in controller(MVC 2 aspx):
<form action="DisplayCustomer" method="post"> Customer id:- <input type="text" id="Customerid" /><br /> Customer Code:- <input type="text" id="code" /><br /> Customer amount:- <input type="text" id="amount" /><br /> <input type="submit" value="click here" /> </form>
This is the view. When someone hit the submit button it is directed to a new page:
<div> <b> ID</b> <%= Model.Id %><br /> <b> Code </b><%=Model.CustomerCode %><br /> <b> Amount</b> <%=Model.Amount %><br /> </div>
I always get 0 in Id and Amount while blank in CustomerCode.
Any clue? Why this is happening? What is wrong?
-
Aristos almost 12 years@shaleen You are welcome. I do not know if you have made a design error here as Slaks say, because I am not work with mvc. I only know that this is the reason that you not get the form values as I see your code.