Following are controller and view. When [submit] button is being click application raises a error “resource can not found”. I know using Get and Post is very basic concept of MVC. Would any make me the concept clear with some practical scenario when to use Get and Post and WHAT IS WRONG WITH FOLLOWING CODES.
Controller:
namespace MVCModelBinding.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost, ActionName("Index")]
public ActionResult IndexPost()
{
if (Request.Form.Count > 0)
{
string id = Request.Form["ID"];
string fname = Request.Form["FirstName"];
string lname = Request.Form["LastName"];
ViewBag.StatusMessage = "Employee data received successfully for ID " + id + "!";
}
return View();
}
public ActionResult About()
{
return View();
}
}
}
view (index.chtml)
@using (Html.BeginForm("IndexPost", "HomeController",FormMethod.Post))
{
<table>
<tr>
<td>
Employee ID
</td>
<td>
@Html.TextBox("ID")
</td>
</tr>
<tr>
<td>
First name
</td>
<td>
@Html.TextBox("FirstName")
</td>
</tr>
<tr>
<td>
Last Name
</td>
<td>
@Html.TextBox("LastName")
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit" />
</td>
</tr>
</table>
}
Thanks
Paul
The action name and controller name used for the form are wrong. It should be
The action name is just
"Index"because that’s what you specified withActionNameAttribute. The controller name should not include the “Controller” suffix.