你必須發回一個形式的源代碼是這樣的: 型號/ Yourmodel.cs:
public class FooModel
{
public int Metric { get; set; }
}
你的控制器:
public ViewResult InputTest() {
return View();
}
[HttpPost]
public ActionResult SubmitInputTest(FooModel model) {
//your code
//do stuff
return RedirectToAction("index");
}
您的頁面:
@model MVCWebApp.Models.FooModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>InputTest</title>
</head>
<body>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
@using (Html.BeginForm("SubmitInputTest","Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>FooModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Metric, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Metric, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Metric, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
</body>
</html>
它可能應該是的'客戶''而不是CustomersController'。 –