asp.net的request.form [英] asp.net request.form
本文介绍了asp.net的request.form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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);
}
这是我在控制器操作(MVC 2 ASPX):
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>
我总是在标识得到0和金额,而在客户code空白。
I always get 0 in Id and Amount while blank in CustomerCode.
任何线索?为什么会这样?什么是错的?
Any clue? Why this is happening? What is wrong?
推荐答案
在这里你的问题是,你将 ID
,而不是名称
。将名称设置为获得后回值。例如:
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" />
阅读也: HTML输入 - 名称与所使用的线ID 对表单元素提交信息
这篇关于asp.net的request.form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文