为了验证,我决定尝试使用@Html。TextBoxFor
,因此验证既快捷又简单。但是,没有设置值的选项,我假设它是自动完成的,但它不是自动设置的。
控制器:
MyLibrary.MyProspect prospect = MyLib.GetProspect(ID);
return View(prospect);
视图:
@model MyLibrary.MyProspect
@using (Html.BeginForm("Update", "Prospects"))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Edit</legend>
@Html.LabelFor(model => model.Name)
@Html.TextBoxFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
我对Prospect的库定义:
public class MyProspect
{
public String Name { get; set; }
}
我的猜测是,在任何时候我都不会将模型设置为真正的潜在客户。但我没有遇到过这样的例子,我想我会像现在这样忽略它吗?
SOLVED This is working code, Id just mixed and matched my controller action to the wrong view.