在 Mvc 应用程序中,我创建了一个简单的应用程序 HttGet、HttpPost 但无法正常工作。这是我的代码:
模型:
public class SasiClass
{
public int SasiId { get; set; }
public string SasiName { get; set; }
public string SasiAddress { get; set; }
}
控制器:
[HttpGet]
public ActionResult CreateSasi()
{
SasiClass objSasi = new SasiClass();
return View(objSasi);
}
[HttpPost]
public ActionResult CreateSasi(SasiClass obj)
{
return View("Show",obj);
}
视图:创建萨西:
@using (Html.BeginForm("CreateSasi", "Home"))
{
<table >
<tr>
<td>Sasi ID</td>
<td>@Html.TextBox("SasiId",@Model.SasiId ) </td>
</tr>
<tr>
<td>Sasi Name</td>
<td>@Html.TextBox("SasiName",@Model.SasiName) </td>
</tr>
<tr>
<td>Sasi Address</td>
<td>@Html.TextBox("SasiAddress",@Model.SasiAddress) </td>
</tr>
<tr>
<td colspan="2">@Html.ActionLink("Submit","CreateSasi") </td>
</tr>
</table>
}
显示:查看
<table>
<tr>
<td>Id: </td>
<td>@Model.SasiId</td>
</tr>
<tr>
<td>Name: </td>
<td>@Model.SasiName</td>
</tr>
<tr>
<td>Address: </td>
<td>@Html.TextBox("address", @Model.SasiAddress)</td>
</tr>