以下是我的观看代码。从此返回的客户类对象为null。我是mvc。
的初学者@model WebApplication2.Models.Customer
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>InputCustomerWithHelper</title>
</head>
<body>
<div>
@using(Html.BeginForm("DisplayCustomerWith","First",FormMethod.Post))
{
<p>Customer Name @Html.TextBoxFor(n=>n.customerName)</p>
<p>Customer ID @Html.TextBoxFor(n=>n.customerId)</p>
<p> Amount to be Paid @Html.TextBoxFor(n=>n.amount)</p>
<input type="submit" value="Submit Data" />
}
</div>
</body>
</html>
从文本框中添加控制器代码,型号代码和查看显示值代码。
public class Customer
{
public string customerName;
public int customerId;
public decimal amount;
}
文本框值显示代码
<div>
Customer Name : @Model.customerName
Customer ID : @Model.customerId
Amount : @Model.amount
</div>
控制器代码
public ActionResult InputCustomerWithHelper()
{
return View();
}
[HttpPost]
public ActionResult DisplayCustomerWith(Customer obj)
{
return View("LoadCustomerData",obj);
}
答案 0 :(得分:0)
您必须使用相同的模型添加动作:
//Action should be POST method "DisplayCustomerWith" and Controller will be "First" with "Customer" model
[HttpPost]
public ActionResult DisplayCustomerWith(Customer objCustomer)
{
return view();
}
Hope this will help you !!!