以下是管制者和观点。 当[提交]纽扣申请时,“无法找到资源”就会产生错误。 我知道使用“Get and Post”是MVC的根本概念。 如果有的话,在使用“Get and Post and WHAT IS FRAONG 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>
}
成就
Paul