In your view
@using (Html.BeginForm("Add", "Weight", FormMethod.Post))
//where "Add" is the Action name and Weight is the controller (WeightController) -> http://foo/Weight
{
......
}
With a model
public class WeightModel
{
[Required] public string Description { get; set; }
[Required] public int Weight { get; set; }
public string Notes { get; set; }
}
In your Controller
[HttpPost]
public ActionResult Add(WeightModel model)
{
if (!ModelState.IsValid) //framwork will validate based on attributes on model
{
return View("Index", model);
}
else
{
//save to db
return RedirectToAction("Added");
}
}