Reputation: 30293
In Mvc application, i created a simple application, HttGet, HttpPost but not working. This is my code:
Model:
public class SasiClass
{
public int SasiId { get; set; }
public string SasiName { get; set; }
public string SasiAddress { get; set; }
}
Controller:
[HttpGet]
public ActionResult CreateSasi()
{
SasiClass objSasi = new SasiClass();
return View(objSasi);
}
[HttpPost]
public ActionResult CreateSasi(SasiClass obj)
{
return View("Show",obj);
}
View: Create Sasi:
@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>
}
Show: View
<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>
Upvotes: 1
Views: 741
Reputation: 26930
you should have SasiId instead of Id in view
<td>@Html.TextBox("SasiId",@Model.SasiId ) </td>
EDIT!!!
You should submit form, instead you are linking to action! This is false in this case:
<td colspan="2">@Html.ActionLink("Submit","CreateSasi") </td>
Do like this:
<td colspan="2"><input type="submit"/> </td>
Upvotes: 2