我正在尝试构建一个简单的ASP.net MVC应用程序。
我的控制器如下所示。
namespace CustomerReadAndLoad.Controllers
{
public class CustomerController : Controller
{
//
// GET: /Customer/
public ActionResult Index()
{
return View();
}
public ActionResult LoadCustomer()
{
return View();
}
[HttpPost]
public ActionResult DisplayCustomer()
{
Customer obj = new Customer();
obj.ID = Convert.ToInt16(Request.Form["CuatomerID"]);
obj.Name = Convert.ToString(Request.Form["CuatomerName"]);
obj.Amount = Convert.ToInt16(Request.Form["CuatomerAmount"]);
return View(obj);
}
}
}
我尝试在LoadCustomerView中包含动作DisplayCustomer,如下所示
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>LoadCustomer</title>
</head>
<body>
<div>
<form action ="DisplayCustomer" method ="post">
Welcome to Customer management System<br />
Enter the below details <br />
Customer ID :- <input type="text" name = "CuatomerID" /><br />
Customer Name :- <input type="text" name = "CuatomerName" /><br />
Customer Amount :- <input type="text" name = "CuatomerAmount" /><br />
<input type ="button" value="ClickHere" />
</form>
</div>
点击“提交”按钮后,我无法移动到视图DisplayCustomer。
答案 0 :(得分:0)
试试这个:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>LoadCustomer</title>
</head>
<body>
<div>
<%using(Html.BeginForm("DisplayCustomer", "Customer", FormMethod.Post)){%>
Welcome to Customer management System<br />
Enter the below details <br />
Customer ID :- <input type="text" name = "CuatomerID" /><br />
Customer Name :- <input type="text" name = "CuatomerName" /><br />
Customer Amount :- <input type="text" name = "CuatomerAmount" /><br />
<button type ="submit">"ClickHere"</button>
<%}%>
</div>